#// Autor= Alejandro Iovane / Dreadblitz
#// Fecha= 07/12/2019
# study(shorttitle="VVI_VRI", title="VELAS ROJAS Y VERDES IGNORADAS DE OLIVER VELEZ", overlay=true)
# Converted by Sam4Cok@Samer800 - 11/2023 - Request from UseThinkScript.com memeber
input modo_tipo = {default "Complete Filter", "Trend Filter", "No Filter"};
input showIgnoredRedCandles = yes;#, "VER VELAS ROJAS IGNORADAS - VRI")
input showIgnoredGreenCandles = yes;#, "VER VELAS VERDES IGNORADAS - VVI")
input showSlowMovAvg = yes;#, title="VER MEDIA LENTA 🐢")
input slowMovAvgType = {default "SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "Hull", "ZEMA", "TMA", "SSMA"};
input slowMovAvgLength = 20;#, title="🔹 Periodo = ", minval=1)
input slowMovAvgSource = close;#, title="🔹 Fuente =")
input slowMovAvgTrendLookback = 1;#, title="🔹 Reaccion =", minval=1)
input showFastMovAvg = yes;#, title="VER MEDIA RAPIDA 🐇")
input fastMovAvgType = {default "SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "Hull", "ZEMA", "TMA", "SSMA"};
input fastMovAvgLength = 8;#, title="🔹 Periodo =", minval=1)
input fastMovAvgSource = close;#, title="🔹 Fuente =")
input fastMovAvgTrendLookback = 1;#, title="🔹 Reaccion =", minval=1)
input uptrendCond = {"NO CONDITION", "PRICE ABOVE FAST MA", "PRICE ABOVE SLOW MA", "PRICE ABOVE FAST/SLOW MA", "PRICE ABOVE SLOW MA AND BULLISH", "PRICE ABOVE FAST MA AND BULLISH", "PRICE ABOVE SLOW/FAST MA AND BULLISH", "SLOW MA BULLISH DIRECTION", "FAST MA BULLISH DIRECTION", default "AVG SLOW/FAST MA BULLISH DIRECTION"};
input downtrendCond = {"NO CONDITION", "PRICE BELOW FAST MA", "PRICE BELOW SLOW MA", "PRICE BELOW FAST/SLOW MA", "PRICE BELOW SLOW MA AND BEARISH", "PRICE BELOW FAST MA AND BEARISH", "PRICE BELOW SLOW/FAST MA AND BEARISH", "SLOW MA BEARISH DIRECTION", "FAST MA BEARISH DIRECTION", default "AVG SLOW/FAST MA BEARISH DIRECTION"};
input minBarBodyPer = 30;#, title="🔹 PORCENTAJE DE CUERPO MINIMO % =", minval=1, maxval=99)
#input colorBar = no;#, title="PINTAR BARRA DE CONTROL")
#input VEBC = no;#, title="VER ETIQUETA BARRA DE CONTROL")
input minIgnoredBarBodyPer = 30;#, title="🔹 ARRIBA DE X% DE LA BARRA DE CONTROL =", minval=0, maxval=99)
#input PBI = no;#, title="PINTAR BARRA IGNORADA")
input overrideMinIgnoredBar = no;#, title="NO PUEDE ANULAR EL MINIMO DE LA BARRA IGNORADA")
input colorSignalBar = no;#, title="PINTAR BARRA DE SEÑAL")
#input VEBS = yes;#, title="VER FLECHA")
#input VO = yes;#, title="VER OSO 🐻 Y FLECHA")
#input VT = yes;#, title="VER TORO 🐂 Y FLECHA")
input showTpSlLines = yes;#, title="VER STOP LOSS Y TAKE PROFIT RECOMENDADO ")
input trendDirection = {default "Bull", "Bear"}; # input(defval="VRI", title="🔹 PARA =", options=)
input extendSlLineBy = 4;#, title="🔹 EXTENDER LINEA STOP LOSS X BARRAS =", minval=1, maxval=99)
input extendTpLineBy = 6;#, title="🔹 EXTENDER LINEA TAKE PROFIT X BARRAS =", minval=1, maxval=99)
input slMulti = 1;#, title="🔹 RATIO PARA MOVER A BREAK EVEN =", minval=1, maxval=10,step=0.1)
input TakeProfit1Multi = 2;#, title="🔹 RATIO TAKE PROFIT 1 =", minval=1, maxval=10,step=0.1)
input TakeProfit2Multi = 4;#, title="🔹 RATIO TAKE PROFIT 2 =", minval=2, maxval=10,step=0.1)
def na = Double.NaN;
def VRI_ON = showIgnoredRedCandles;
def VVI_ON = showIgnoredGreenCandles;
DefineGlobalColor("negro", Color.BLACK);#=#000000
DefineGlobalColor("blanco", CreateColor(253, 254, 254));#=#FDFEFE
DefineGlobalColor("rojo", Color.RED);#=#FF0000
DefineGlobalColor("verde", CreateColor(0, 255, 19));#=#00FF13
DefineGlobalColor("verde_fuerte", CreateColor(10, 172, 0));#=#0AAC00
DefineGlobalColor("azul", CreateColor(0, 0, 255));#=#0000ff
DefineGlobalColor("violeta", CreateColor(79, 5, 79));#=#4f054f
script rising{
input src = close;
input len = 3;
def cnt = fold i = 0 to len with p=1 while p do
GetValue(src, i) > GetValue(src, i+1);
plot rising = cnt;
}
script falling{
input src = close;
input len = 3;
def cnt = fold i = 0 to len with p=1 while p do
GetValue(src, i) < GetValue(src, i+1);
plot falling = cnt;
}
script VWMA {
input src = close;
input len = 14;
input vol = volume;
def nom = Average(src * vol, len);
def den = Average(vol, len);
def VWMA = nom / den;
plot result = VWMA;
}
script supersmoother {
input src = close;
input len = 14;
def pi = 1.414 * Double.Pi;
def a1 = Exp(- pi / len);
def b1 = 2 * a1 * Cos(pi / len);
def c2 = b1;
def c3 = (-a1) * a1;
def c1 = 1 - c2 - c3;
def v9 = if IsNaN(src + src[1]) then v9[1] else
c1 * ( src + src[1]) / 2 + c2 * v9[1] + c3 * v9[2];
plot out = if !IsNaN(src) then v9 else Double.NaN;
}
script smoothed {
input src = close;
input len = 14;
def sma = Average(src, len);
def v5 = if !v5[1] then sma else (v5[1] * (len - 1) + src) / len;
plot out = v5;
}
script zerolagema {
input src = close;
input len = 14;
def ema1 = ExpAverage(src, len);
def ema2 = ExpAverage(ema1, len);
def v10 = ema1 + (ema1 - ema2);
plot out = v10;
}
script variant {
input type = "SMA";
input src = close;
input len = 14;
def variant =
if type == "SMA" then Average(src, len) else
if type == "EMA" then ExpAverage(src, len) else
if type == "WMA" then WMA(src, len) else
if type == "VWMA" then vwma(src, len) else
if type == "SMMA" then smoothed(src, len) else
if type == "DEMA" then DEMA(src, len) else
if type == "TEMA" then TEMA(src, len) else
if type == "Hull" then HullMovingAvg(src, len) else
if type == "SSMA" then supersmoother(src, len) else
if type == "ZEMA" then zerolagema(src, len) else
if type == "TMA" then Average(Average(src, len), len) else Average(src, len);
plot out = variant;
}
def VRI_0 = close[2] > open[2] and open[1] > close[1] and close[0] > open[0];
def VVI_0 = open[2] > close[2] and close[1] > open[1] and open[0] > close[0];
def VRI_1 = VRI_0 and high[0] >= open[1];
def VVI_1 = VVI_0 and low[0] <= open[1];
def VRI_2 = VRI_1 and low[1] > low[2];
def VVI_2 = VVI_1 and high[1] < high[2];
def ma_series = variant(slowMovAvgType, slowMovAvgSource, slowMovAvgLength);# // media lenta
def ma_series_b = variant(fastMovAvgType, fastMovAvgSource, fastMovAvgLength);# // media rapida
def direction = if rising(ma_series,slowMovAvgTrendLookback) then 1 else
if falling(ma_series,slowMovAvgTrendLookback) then -1 else direction[1];
def change_direction= direction - direction[1];
def direction_b = if rising(ma_series_b,fastMovAvgTrendLookback) then 1 else
if falling(ma_series_b,fastMovAvgTrendLookback) then -1 else direction_b[1];
def change_direction_b = direction_b - direction_b[1];
def pcol = if direction>0 then 1 else
if direction<0 then -1 else 0;
def pcol_b = if direction_b>0 then 1 else
if direction_b<0 then -1 else 0;
def PMAMR = uptrendCond == uptrendCond."PRICE ABOVE FAST MA" and close > ma_series_b;
def PMAML = uptrendCond == uptrendCond."PRICE ABOVE SLOW MA" and close > ma_series;
def PMAMRYL = uptrendCond == uptrendCond."PRICE ABOVE FAST/SLOW MA" and close > ma_series and close > ma_series_b;
def PMAMLYDA = uptrendCond == uptrendCond."PRICE ABOVE SLOW MA AND BULLISH" and close > ma_series and direction > 0;
def PMAMRYDA = uptrendCond == uptrendCond."PRICE ABOVE FAST MA AND BULLISH" and close > ma_series_b and direction_b > 0;
def PMAMLRYDA = uptrendCond == uptrendCond."PRICE ABOVE SLOW/FAST MA AND BULLISH" and close > ma_series and close > ma_series_b and direction > 0 and direction_b > 0;
def DMLA = uptrendCond == uptrendCond."SLOW MA BULLISH DIRECTION" and direction > 0;
def DMRA = uptrendCond == uptrendCond."FAST MA BULLISH DIRECTION" and direction_b > 0;
def DMLRA = uptrendCond == uptrendCond."AVG SLOW/FAST MA BULLISH DIRECTION" and direction > 0 and direction_b > 0;
def NCA = uptrendCond == uptrendCond."NO CONDITION";
def PMEAMR = downtrendCond == downtrendCond."PRICE BELOW FAST MA" and close < ma_series_b;
def PMEAML = downtrendCond == downtrendCond."PRICE BELOW SLOW MA" and close < ma_series;
def PMEAMRYL = downtrendCond == downtrendCond."PRICE BELOW FAST/SLOW MA" and close < ma_series and close < ma_series_b;
def PMEAMLYDB = downtrendCond == downtrendCond."PRICE BELOW SLOW MA AND BEARISH" and close < ma_series and direction < 0;
def PMEAMRYDB = downtrendCond == downtrendCond."PRICE BELOW FAST MA AND BEARISH" and close < ma_series_b and direction_b < 0;
def PMEAMLRYDB = downtrendCond == downtrendCond."PRICE BELOW SLOW/FAST MA AND BEARISH" and close < ma_series and close < ma_series_b and direction < 0 and direction_b < 0;
def DMLB = downtrendCond == downtrendCond."SLOW MA BEARISH DIRECTION" and direction < 0;
def DMRB = downtrendCond == downtrendCond."FAST MA BEARISH DIRECTION" and direction_b < 0;
def DMLRB = downtrendCond == downtrendCond."AVG SLOW/FAST MA BEARISH DIRECTION" and direction < 0 and direction_b < 0;
def NCB = downtrendCond == downtrendCond."NO CONDITION";
def VRI_3 = if VRI_2 and PMAMR then yes else
if VRI_2 and PMAML then yes else
if VRI_2 and PMAMRYL then yes else
if VRI_2 and PMAMLYDA then yes else
if VRI_2 and PMAMRYDA then yes else
if VRI_2 and PMAMLRYDA then yes else
if VRI_2 and DMLA then yes else
if VRI_2 and DMRA then yes else
if VRI_2 and DMLRA then yes else
if VRI_2 and NCA then yes else no;
def VVI_3 = if VVI_2 and PMEAMR then yes else
if VVI_2 and PMEAML then yes else
if VVI_2 and PMEAMRYL then yes else
if VVI_2 and PMEAMLYDB then yes else
if VVI_2 and PMEAMRYDB then yes else
if VVI_2 and PMEAMLRYDB then yes else
if VVI_2 and DMLB then yes else
if VVI_2 and DMRB then yes else
if VVI_2 and DMLRB then yes else
if VVI_2 and NCB then yes else no;
def VRI_3_A = if VRI_1 and PMAMR then yes else
if VRI_1 and PMAML then yes else
if VRI_1 and PMAMRYL then yes else
if VRI_1 and PMAMLYDA then yes else
if VRI_1 and PMAMRYDA then yes else
if VRI_1 and PMAMLRYDA then yes else
if VRI_1 and DMLA then yes else
if VRI_1 and DMRA then yes else
if VRI_1 and DMLRA then yes else
if VRI_1 and NCA then yes else no;
def VVI_3_A = if VVI_1 and PMEAMR then yes else
if VVI_1 and PMEAML then yes else
if VVI_1 and PMEAMRYL then yes else
if VVI_1 and PMEAMLYDB then yes else
if VVI_1 and PMEAMRYDB then yes else
if VVI_1 and PMEAMLRYDB then yes else
if VVI_1 and DMLB then yes else
if VVI_1 and DMRB then yes else
if VVI_1 and DMLRB then yes else
if VVI_1 and NCB then yes else no;
#// 3- BARRA DE CONTROL CON UN CUERPO DE AL MENOS UN 55% (o valor configurado)
def VRI_4 = VRI_3 and AbsValue(open[2]-close[2]) *100/ AbsValue(high[2]-low[2]) >= minBarBodyPer;
def VVI_4 = VVI_3 and AbsValue(open[2]-close[2]) *100/ AbsValue(high[2]-low[2]) >= minBarBodyPer;
#// 4- BARRA IGNORADA ESTRECHA ARRIBA DEL 70% SUPERIOR DE LA BARRA DE CONTROL (o valor configurado)
def VRI_5 = VRI_4 and AbsValue(low[1]-low[2])*100/AbsValue(high[2]-low[2]) >= minIgnoredBarBodyPer;
def VVI_5 = VVI_4 and AbsValue(high[1]-high[2])*100/AbsValue(high[2]-low[2]) >= minIgnoredBarBodyPer;
#// 5- BARRA DE SEÑAL NO PUEDE ANULAR EL MINIMO DE LA BARRA IGNORADA
def VRI_6 = if VRI_5 and overrideMinIgnoredBar and low[0] >= low[1] then yes else
if VRI_5 and !overrideMinIgnoredBar then yes else no;
def VVI_6 = if VVI_5 and overrideMinIgnoredBar and high[0] <= high[1] then yes else
if VVI_5 and !overrideMinIgnoredBar then yes else no;
#// RESULTADO
def RES_VRI = if VRI_6 and VRI_ON and modo_tipo == modo_tipo."Complete Filter" then yes else
if VRI_1 and VRI_ON and modo_tipo == modo_tipo."No Filter" then yes else
if VRI_3_A and VRI_ON and modo_tipo == modo_tipo."Trend Filter" then yes else no;
def RES_VVI = if VVI_6 and VVI_ON and modo_tipo == modo_tipo."Complete Filter" then yes else
if VVI_1 and VVI_ON and modo_tipo == modo_tipo."No Filter" then yes else
if VVI_3_A and VVI_ON and modo_tipo == modo_tipo."Trend Filter" then yes else no;
AddChartBubble(RES_VRI, low, "️VRI", GlobalColor("verde_fuerte"), no);
AddChartBubble(RES_VVI, high, "️VVI", GlobalColor("rojo"));
plot ma1 = if showSlowMovAvg then ma_series else na;#, color=pcol
plot ma2 = if showFastMovAvg then ma_series_b else na;#, color=pcol_b
ma1.AssignValueColor(if pcol>0 then GlobalColor("verde") else
if pcol<0 then GlobalColor("rojo") else Color.GRAY);
ma2.AssignValueColor(if pcol_b>0 then GlobalColor("verde") else
if pcol_b<0 then GlobalColor("rojo") else Color.GRAY);
AssignPriceColor(if !colorSignalBar then Color.CURRENT else
if RES_VRI then Color.CYAN else
if RES_VVI then Color.MAGENTA else Color.CURRENT);
#/ TOMA DE GANANCIA / PERDIDA RECOMENDADAS
def atr = atr(Length = 50) * 0.5;
#dt = time - time[1]
def UR_VRI = AbsValue(open[1] - low[1]);
def BE_VRI = open[1] + UR_VRI * slMulti;
def TP1_VRI= open[1] + UR_VRI * TakeProfit1Multi;
def TP2_VRI= open[1] + UR_VRI * TakeProfit2Multi;
def UR_VVI = AbsValue(open[1] - high[1]);
def BE_VVI = open[1] - UR_VVI * slMulti;
def TP1_VVI= open[1] - UR_VVI * TakeProfit1Multi;
def TP2_VVI= open[1] - UR_VVI * TakeProfit2Multi;
def vriLine1; def vriLine2; def vriLine3; def vriLine4;def vriCnt;
if RES_VRI == 1 and showTpSlLines and trendDirection == trendDirection."Bull" {
vriCnt = 0;
vriLine1 = low[1];
vriLine2 = BE_VRI;
vriLine3 = TP1_VRI;
vriLine4 = TP2_VRI;
} else {
vriCnt = vriCnt[1] + 1;
vriLine1 = if vriCnt > extendSlLineBy + 1 then na else vriLine1[1];
vriLine2 = if vriCnt > extendTpLineBy + 3 then na else vriLine2[1];
vriLine3 = if vriCnt > extendTpLineBy + 3 then na else vriLine3[1];
vriLine4 = if vriCnt > extendTpLineBy + 3 then na else vriLine4[1];
}
plot vriSL = vriLine1[-1];
plot vriEntry = vriLine2[-3];
plot vriTp1 = vriLine3[-3];
plot vriTp2 = vriLine4[-3];
vriSL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vriEntry.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vriTp1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vriTp2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vriSL.SetDefaultColor(Color.MAGENTA);
vriEntry.SetDefaultColor(color.GRAY);
vriTp1.SetDefaultColor(Color.CYAN);
vriTp2.SetDefaultColor(Color.CYAN);
def vviLine1; def vviLine2; def vviLine3; def vviLine4;def vviCnt;
if RES_VVI == 1 and showTpSlLines and trendDirection == trendDirection."Bear" {
vviCnt = 0;
vviLine1 = high[1];
vviLine2 = BE_VVI;
vviLine3 = TP1_VVI;
vviLine4 = TP2_VVI;
} else {
vviCnt = vviCnt[1] + 1;
vviLine1 = if vviCnt > extendSlLineBy + 1 then na else vviLine1[1];
vviLine2 = if vviCnt > extendTpLineBy + 3 then na else vviLine2[1];
vviLine3 = if vviCnt > extendTpLineBy + 3 then na else vviLine3[1];
vviLine4 = if vviCnt > extendTpLineBy + 3 then na else vviLine4[1];
}
plot vviSL = vviLine1[-1];
plot vviEntry = vviLine2[-3];
plot vviTp1 = vviLine3[-3];
plot vviTp2 = vviLine4[-3];
vviSL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vviEntry.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vviTp1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vviTp2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vviSL.SetDefaultColor(Color.MAGENTA);
vviEntry.SetDefaultColor(color.GRAY);
vviTp1.SetDefaultColor(Color.CYAN);
vviTp2.SetDefaultColor(Color.CYAN);
#-- END of CODE