Está en la página 1de 8

CÓDIGO PINE EDITOR DE LA ESTRATEGIA

AUTOMATIZADA “TAV2-ST-QQE”
LINK DEL VIDEO PARA ESTE CÓDIGO:
https://www.youtube.com/watch?v=el1cpqSK4YM

SI FUE ÚTIL PARA TI ESTA ESTRATEGIA, LO ÚNICO QUE TE PIDO ES QUE


LA COMPARTAS.
¡UN ABRAZO!, ANDRÉS.

//@version=5
indicator("TAV2-ST-QQE", shorttitle = "AV2STQQE", overlay = true)
//INDICATOR CREATED BY ANDRES ARISTIZABAL, 14 MAY 2022

//TREND INDICATOR A-V2 CREATED BY Dziwne


ma_type = input.string(title="MA Type", defval="VWMA", options=["EMA", "SMA",
"SWMA", "VWMA", "WMA"])
ma_period = input.int(title="MA Period (Length)", defval=52, minval=1)
ma_period_smoothing = input.int(title="MA Period smoothing (Length)", defval=10,
minval=1)

color_positive = input(title="Positive color (Bullish)", defval=color.new(#26A69A, 50) )


color_negative = input(title="Negative color (Bearish)", defval=color.new(#EF5350, 50) )
color_hl = input(title="High & Low cloud color", defval=color.new(#808080, 80) )

show_line = input(title="Show (lines)", defval=false)


show_hl_cloud = input(title="Show (High & Low cloud)", defval=true)
show_oc_cloud = input(title="Show (Open & Close cloud)", defval=true)

//
————————————————————————————————————————
————————————————————————————————————————
// I.2. Settings, Function definition
——————————————————————
//
————————————————————————————————————————
————————————————————————————————————————

f_ma_type(input_ma_type, input_source, input_ma_period) =>


result = float(na)

if input_ma_type == "EMA"
result := ta.ema(input_source, input_ma_period)
result
if input_ma_type == "SMA"
result := ta.sma(input_source, input_ma_period)
result
if input_ma_type == "SWMA"
result := ta.swma(input_source)
result
if input_ma_type == "VWMA"
result := ta.vwma(input_source, input_ma_period)
result
if input_ma_type == "WMA"
result := ta.wma(input_source, input_ma_period)
result

result

//
————————————————————————————————————————
————————————————————————————————————————
// II.1. Calculations, MA — — — — — — — — — — — — — — — — — — — — — — — —
————
//
————————————————————————————————————————
————————————————————————————————————————

o = f_ma_type(ma_type, open, ma_period)


c = f_ma_type(ma_type, close, ma_period)
h = f_ma_type(ma_type, high, ma_period)
l = f_ma_type(ma_type, low, ma_period)

//
————————————————————————————————————————
————————————————————————————————————————
// II.2. Calculations, Heikin Ashi
————————————————————————
//
————————————————————————————————————————
————————————————————————————————————————

ha = ticker.heikinashi(syminfo.tickerid)
ha_o = request.security(ha, timeframe.period, o)
ha_c = request.security(ha, timeframe.period, c)
ha_h = request.security(ha, timeframe.period, h)
ha_l = request.security(ha, timeframe.period, l)

//
————————————————————————————————————————
————————————————————————————————————————
// II.3. Calculations, MA (Smoothing)
——————————————————————
//
————————————————————————————————————————
————————————————————————————————————————

ha_o_smooth = f_ma_type(ma_type, ha_o, ma_period_smoothing)


ha_c_smooth = f_ma_type(ma_type, ha_c, ma_period_smoothing)
ha_h_smooth = f_ma_type(ma_type, ha_h, ma_period_smoothing)
ha_l_smooth = f_ma_type(ma_type, ha_l, ma_period_smoothing)

//
————————————————————————————————————————
————————————————————————————————————————
// III.1. Display, Colors
————————————————————————————
//
————————————————————————————————————————
————————————————————————————————————————

trends = ha_c_smooth >= ha_o_smooth

color_trend = trends ? color_positive : color_negative

color_show_line_positive = show_line ? color_positive : na


color_show_line_negative = show_line ? color_negative : na

color_show_hl_cloud = show_hl_cloud ? color_hl : na


color_show_oc_cloud = show_oc_cloud ? color_trend : na

//
————————————————————————————————————————
————————————————————————————————————————
// III.2. Display, Plotting & Filling — — — — — — — — — — — — — — — — — — — — —

//
————————————————————————————————————————
————————————————————————————————————————

o_line = plot(ha_o_smooth, color=color_show_line_positive, title="Open line")


c_line = plot(ha_c_smooth, color=color_show_line_negative, title="Close line")

h_line = plot(ha_h_smooth, color=color_show_line_positive, title="High line")


l_line = plot(ha_l_smooth, color=color_show_line_negative, title="Low line")

fill(o_line, c_line, color=color_show_oc_cloud, title="Open & Close Trendcloud")


fill(h_line, l_line, color=color_show_hl_cloud, title="High & Low Trendcloud")

//SUPERTREND INDICATOR CREATED BY KivancOzbilgic


Periods = input.int(title="ATR Period", defval=9, minval=1)
src1 = input(hl2, title="Source")
Multiplier = input.float(title="ATR Multiplier", step=0.1, defval=3.9)
changeATR= input.bool(title="Change ATR Calculation Method ?", defval=true)
showsignals = input.bool(title="Show Buy/Sell Signals ?", defval=false)
highlighting = input.bool(title="Highlighter On/Off ?", defval=true)
barcoloring = input.bool(title="Bar Coloring On/Off ?", defval=true)
atr2 = ta.sma(ta.tr, Periods)
atr= changeATR ? ta.atr(Periods) : atr2
up=src1-(Multiplier*atr)
up1 = nz(up[1],up)
up := close[1] > up1 ? math.max(up,up1) : up
dn=src1+(Multiplier*atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? math.min(dn, dn1) : dn
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2,
color=color.green)
buySignal = trend == 1 and trend[1] == -1
plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute,
style=shape.circle, size=size.tiny, color=color.green, transp=0)
plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy",
location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green,
textcolor=color.white, transp=0)
dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr,
linewidth=2, color=color.red)
sellSignal = trend == -1 and trend[1] == 1
plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute,
style=shape.circle, size=size.tiny, color=color.red, transp=0)
plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell",
location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red,
textcolor=color.white, transp=0)
mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
longFillColor = highlighting ? (trend == 1 ? color.green : color.white) : color.white
shortFillColor = highlighting ? (trend == -1 ? color.red : color.white) : color.white
fill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor)
fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)
FromMonth = input.int(defval = 9, title = "From Month", minval = 1, maxval = 12)
FromDay = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)
FromYear = input.int(defval = 2018, title = "From Year", minval = 999)
ToMonth = input.int(defval = 1, title = "To Month", minval = 1, maxval = 12)
ToDay = input.int(defval = 1, title = "To Day", minval = 1, maxval = 31)
ToYear = input.int(defval = 9999, title = "To Year", minval = 999)
start = timestamp(FromYear, FromMonth, FromDay, 00, 00)
finish = timestamp(ToYear, ToMonth, ToDay, 23, 59)
window() => time >= start and time <= finish ? true : false
longCondition = buySignal
//if (longCondition)
// strategy.entry("BUY", strategy.long, when = window())
shortCondition = sellSignal
//if (shortCondition)
// strategy.entry("SELL", strategy.short, when = window())
buy1= ta.barssince(buySignal)
sell1 = ta.barssince(sellSignal)
color1 = buy1[1] < sell1[1] ? color.green : buy1[1] > sell1[1] ? color.red : na
barcolor(barcoloring ? color1 : na)

//QQUE MOD INDICATOR CREATED BY Minkel00

RSI_Period = input(6, title='RSI Length')


SF = input(5, title='RSI Smoothing')
QQE = input(3, title='Fast QQE Factor')
ThreshHold = input(3, title="Thresh-hold")
//

src = input(close, title="RSI Source")


//

//
Wilders_Period = RSI_Period * 2 - 1
Rsi = ta.rsi(src, RSI_Period)
RsiMa = ta.ema(Rsi, SF)
AtrRsi = math.abs(RsiMa[1] - RsiMa)
MaAtrRsi = ta.ema(AtrRsi, Wilders_Period)
dar = ta.ema(MaAtrRsi, Wilders_Period) * QQE

longband = 0.0
shortband = 0.0
trend1 = 0

DeltaFastAtrRsi = dar
RSIndex = RsiMa
newshortband = RSIndex + DeltaFastAtrRsi
newlongband = RSIndex - DeltaFastAtrRsi
longband := RSIndex[1] > longband[1] and RSIndex > longband[1] ?
math.max(longband[1], newlongband) : newlongband
shortband := RSIndex[1] < shortband[1] and RSIndex < shortband[1] ?
math.min(shortband[1], newshortband) : newshortband
cross_1 = ta.cross(longband[1], RSIndex)
trend := ta.cross(RSIndex, shortband[1]) ? 1 : cross_1 ? -1 : nz(trend[1], 1)
FastAtrRsiTL = trend == 1 ? longband : shortband
////////////////////

length = input.int(50, minval=1, title="Bollinger Length")


mult = input.float(0.35, minval=0.001, maxval=5, step=0.1, title="BB Multiplier")
basis = ta.sma(FastAtrRsiTL - 50, length)
dev = mult * ta.stdev(FastAtrRsiTL - 50, length)
upper = basis + dev
lower = basis - dev
color_bar = RsiMa - 50 > upper ? #00c3ff : RsiMa - 50 < lower ? #ff0062 : color.gray

//
// Zero cross
QQEzlong = 0
QQEzlong := nz(QQEzlong[1])
QQEzshort = 0
QQEzshort := nz(QQEzshort[1])
QQEzlong := RSIndex >= 50 ? QQEzlong + 1 : 0
QQEzshort := RSIndex < 50 ? QQEzshort + 1 : 0
//
Zero = hline(0, color=color.white, linestyle=hline.style_dotted, linewidth=1)

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

RSI_Period2 = input(6, title='RSI Length')


SF2 = input(5, title='RSI Smoothing')
QQE2 = input(1.61, title='Fast QQE2 Factor')
ThreshHold2 = input(3, title="Thresh-hold")

src2 = input(close, title="RSI Source")


//

//
Wilders_Period2 = RSI_Period2 * 2 - 1

Rsi2 = ta.rsi(src2, RSI_Period2)


RsiMa2 = ta.ema(Rsi2, SF2)
AtrRsi2 = math.abs(RsiMa2[1] - RsiMa2)
MaAtrRsi2 = ta.ema(AtrRsi2, Wilders_Period2)
dar2 = ta.ema(MaAtrRsi2, Wilders_Period2) * QQE2
longband2 = 0.0
shortband2 = 0.0
trend2 = 0

DeltaFastAtrRsi2 = dar2
RSIndex2 = RsiMa2
newshortband2 = RSIndex2 + DeltaFastAtrRsi2
newlongband2 = RSIndex2 - DeltaFastAtrRsi2
longband2 := RSIndex2[1] > longband2[1] and RSIndex2 > longband2[1] ?
math.max(longband2[1], newlongband2) : newlongband2
shortband2 := RSIndex2[1] < shortband2[1] and RSIndex2 < shortband2[1] ?
math.min(shortband2[1], newshortband2) : newshortband2
cross_2 = ta.cross(longband2[1], RSIndex2)
trend2 := ta.cross(RSIndex2, shortband2[1]) ? 1 : cross_2 ? -1 : nz(trend2[1], 1)
FastAtrRsi2TL = trend2 == 1 ? longband2 : shortband2

//
// Zero cross
QQE2zlong = 0
QQE2zlong := nz(QQE2zlong[1])
QQE2zshort = 0
QQE2zshort := nz(QQE2zshort[1])
QQE2zlong := RSIndex2 >= 50 ? QQE2zlong + 1 : 0
QQE2zshort := RSIndex2 < 50 ? QQE2zshort + 1 : 0
//

hcolor2 = RsiMa2 - 50 > ThreshHold2 ? color.silver :


RsiMa2 - 50 < 0 - ThreshHold2 ? color.silver : na
plot(FastAtrRsi2TL - 50, title='QQE Line', color=color.white, transp=0, linewidth=2)
plot(RsiMa2 - 50, color=hcolor2, transp=50, title='Histo2', style=plot.style_columns)

Greenbar1 = RsiMa2 - 50 > ThreshHold2


Greenbar2 = RsiMa - 50 > upper

Redbar1 = RsiMa2 - 50 < 0 - ThreshHold2


Redbar2 = RsiMa - 50 < lower
plot(Greenbar1 and Greenbar2 == 1 ? RsiMa2 - 50 : na, title="QQE Up",
style=plot.style_columns, color=#00c3ff, transp=0)
plot(Redbar1 and Redbar2 == 1 ? RsiMa2 - 50 : na, title="QQE Down",
style=plot.style_columns, color=#ff0062, transp=0)

//SIGNALS
long_signal = ha_o <= ha_c and buy1 [1] > sell1 [1] and RsiMa2 - 50 > ThreshHold2 and
RsiMa - 50 > upper
short_signal = ha_o >= ha_c and buy1 [1] < sell1 [1] and RsiMa2 - 50 < 0 - ThreshHold2 and
RsiMa - 50 < lower

//ALERTS
alertcondition(long_signal, title = "AV2STQQE LARGO", message = "LONG")
alertcondition(short_signal, title = "AV2STQQE CORTO", message = "SHORT")

También podría gustarte