Duda Wilders Average

El espacio del Foro donde compartir indicadores y estrategias creados con el lenguaje de la plataforma TradingView.
Responder
Saylarr
Mensajes: 5
Registrado: 27 May 2021 07:06

Duda Wilders Average

Mensaje por Saylarr »

Hola, soy nuevo en el foro.

He estado intentando traducir un indicador desde ThinkScript a PineScript, pero tengo problemas con las funciones equivalentes. Por ejemplo

Código: Seleccionar todo

WildersAverage(TrueRange(high, close, low), atrLength)
no he logrado traducir eso, ya que no encuentro (si es que la tiene) la WildersAverage en PineScript, alguien me podria decir si es que existe en pinescript?
Tambien me ayudarian si me pudieran decir cual es el equivalente al compoundValue de thinkscript en pinescript?

saludos
Avatar de Usuario
X-Trader
Administrador
Mensajes: 12781
Registrado: 06 Sep 2004 10:18
Contactar:

Re: Duda Wilders Average

Mensaje por X-Trader »

Bienvenido al Foro Saylarr,

Para calcular la media móvil de Wilder (en TradingView denominada Running Moving Average o RMA) debes usar la siguiente función en Pine Script:

Código: Seleccionar todo

rma(sourceData, length)
Sobre el CompoundValue, entiendo que te refieres a esta función, ¿verdad?

https://tlc.thinkorswim.com/center/refe ... poundValue

Dame un rato e intento averiguar si hay algo parecido en PineScript.


Saludos,
X-Trader
"Los sistemas de trading pueden funcionar en ciertas condiciones de mercado todo el tiempo, en todas las condiciones de mercado en algún momento del tiempo, pero nunca en todas las condiciones de mercado todo el tiempo."
Saylarr
Mensajes: 5
Registrado: 27 May 2021 07:06

Re: Duda Wilders Average

Mensaje por Saylarr »

X-Trader escribió: 27 May 2021 11:58 Bienvenido al Foro Saylarr,

Para calcular la media móvil de Wilder (en TradingView denominada Running Moving Average o RMA) debes usar la siguiente función en Pine Script:

Código: Seleccionar todo

rma(sourceData, length)
Sobre el CompoundValue, entiendo que te refieres a esta función, ¿verdad?

https://tlc.thinkorswim.com/center/refe ... poundValue

Dame un rato e intento averiguar si hay algo parecido en PineScript.


Saludos,
X-Trader
Si señor a esa funcion me refiero ! muchas gracias! no sabes lo contento que estoy de encontrar un foro de pine en español! jajajaja.

Tengo 2 dudas mas, el equivalente a la funcion TrueRange en pine cual seria?

Código: Seleccionar todo

TrueRange(high, close, low)
y por ultimo pregunta, porque me estoy matando traduciendolo y quizas alguien ya lo tradujo. Sabes si alguien ya ha traducido este indicador a pine? su nombre es ZigZag High Low y es el que viene por defecto en la plataforma Thinkorswim.

Código: Seleccionar todo

input priceH = high;
input priceL = low;
input percentageReversal = 5.0;
input absoluteReversal = 0.0;
input atrLength = 5;
input atrReversal = 1.5;
input tickReversal = 0;

Assert(percentageReversal >= 0, "'percentage reversal' must not be negative: " + percentageReversal);
Assert(absoluteReversal >= 0, "'absolute reversal' must not be negative: " + absoluteReversal);
Assert(atrReversal >= 0, "'atr reversal' must not be negative: " + atrReversal);
Assert(tickReversal >= 0, "'ticks' must not be negative: " + tickReversal);
Assert(percentageReversal != 0 or absoluteReversal != 0 or atrReversal != 0 or tickReversal != 0, "Either 'percentage reversal' or 'absolute reversal' or 'atr reversal' or 'tick reversal' must not be zero");

def absReversal;
if (absoluteReversal != 0) {
    absReversal = absoluteReversal;
} else {
    absReversal =  tickReversal * TickSize();
}

def hlPivot;
if (atrReversal != 0) {
    hlPivot = percentageReversal / 100 + WildersAverage(TrueRange(high, close, low), atrLength) / close * atrReversal;
} else {
    hlPivot = percentageReversal / 100;
}
def state = {default init, undefined, uptrend, downtrend};
def maxPriceH;
def minPriceL;
def newMax;
def newMin;
def prevMaxH = GetValue(maxPriceH, 1);
def prevMinL = GetValue(minPriceL, 1);

if GetValue(state, 1) == GetValue(state.init, 0) {
    maxPriceH = priceH;
    minPriceL = priceL;
    newMax = yes;
    newMin = yes;
    state = state.undefined;
} else if GetValue(state, 1) == GetValue(state.undefined, 0) {
    if priceH >= prevMaxH {
        state = state.uptrend;
        maxPriceH = priceH;
        minPriceL = prevMinL;
        newMax = yes;
        newMin = no;
    } else if priceL <= prevMinL {
        state = state.downtrend;
        maxPriceH = prevMaxH;
        minPriceL = priceL;
        newMax = no;
        newMin = yes;
    } else {
        state = state.undefined;
        maxPriceH = prevMaxH;
        minPriceL = prevMinL;
        newMax = no;
        newMin = no;
    }
} else if GetValue(state, 1) == GetValue(state.uptrend, 0) {
    if priceL <= prevMaxH - prevMaxH * hlPivot - absReversal {
        state = state.downtrend;
        maxPriceH = prevMaxH;
        minPriceL = priceL;
        newMax = no;
        newMin = yes;
    } else {
        state = state.uptrend;
        if (priceH >= prevMaxH) {
            maxPriceH = priceH;
            newMax = yes;
        } else {
            maxPriceH = prevMaxH;
            newMax = no;
        }
        minPriceL = prevMinL;
        newMin = no;
    }
} else {
    if priceH >= prevMinL + prevMinL * hlPivot + absReversal {
        state = state.uptrend;
        maxPriceH = priceH;
        minPriceL = prevMinL;
        newMax = yes;
        newMin = no;
    } else {
        state = state.downtrend;
        maxPriceH = prevMaxH;
        newMax = no;
        if (priceL <= prevMinL) {
            minPriceL = priceL;
            newMin = yes;
        } else {
            minPriceL = prevMinL;
            newMin = no;
        }
    }
}

def barNumber = BarNumber();
def barCount = HighestAll(If(IsNaN(priceH), 0, barNumber));
def newState = GetValue(state, 0) != GetValue(state, 1);
def offset = barCount - barNumber + 1;
def highPoint = state == state.uptrend and priceH == maxPriceH;
def lowPoint = state == state.downtrend and priceL == minPriceL;

def lastH;
if highPoint and offset > 1 {
    lastH = fold iH = 1 to offset with tH = priceH while !IsNaN(tH) and !GetValue(newState, -iH) do if GetValue(newMax, -iH) or iH == offset - 1 and GetValue(priceH, -iH) == tH then Double.NaN else tH;
} else {
    lastH = Double.NaN;
}

def lastL;
if lowPoint and offset > 1 {
    lastL = fold iL = 1 to offset with tL = priceL while !IsNaN(tL) and !GetValue(newState, -iL) do if GetValue(newMin, -iL) or iL == offset - 1 and GetValue(priceL, -iL) == tL then Double.NaN else tL;
} else {
    lastL = Double.NaN;
}

plot ZZ;
if barNumber == 1 {
    ZZ = fold iF = 1 to offset with tP = Double.NaN while IsNaN(tP) do if GetValue(state, -iF) == GetValue(state.uptrend, 0) then priceL else if GetValue(state, -iF) == GetValue(state.downtrend, 0) then priceH else Double.NaN;
} else if barNumber == barCount {
    ZZ = if highPoint or state == state.downtrend and priceL > minPriceL then priceH else if lowPoint or state == state.uptrend and priceH < maxPriceH then priceL else Double.NaN;
} else {
    ZZ = if !IsNaN(lastH) then lastH else if !IsNaN(lastL) then lastL else Double.NaN;
}
ZZ.SetDefaultColor(GetColor(1));
ZZ.EnableApproximation();
He visto algunos, pero funcionan distinto o cambian, yo necesito que sea exactamente igual porque lo voy a usar para crear otro indicador
Última edición por Saylarr el 27 May 2021 20:03, editado 1 vez en total.
Avatar de Usuario
X-Trader
Administrador
Mensajes: 12781
Registrado: 06 Sep 2004 10:18
Contactar:

Re: Duda Wilders Average

Mensaje por X-Trader »

Hola Saylarr, la función para el True Range es esta:

https://www.tradingview.com/pine-script ... e/#fun_atr

En concreto, la sintaxis es:

Código: Seleccionar todo

atr(length)
Si pones length=1 tienes el True Range en bruto sin promediar.

Sobre el ZigZag, el que he visto más parecido a lo que buscas es este:

https://www.tradingview.com/script/rL52 ... -lucemanb/

Tendrías que modificar las funciones dentro de ese script para incorporar el percentageReversal y el absReversal pero no parece a priori complicado. De todos modos, la pregunta del millón: ¿para que quieres el ZigZag? Es un indicador que repinta, salvo que vayas a contar ondas o similar no sirve de mucho porque altera su comportamiento pasado a medida que se actualiza el precio.


Saludos,
X-Trader
"Los sistemas de trading pueden funcionar en ciertas condiciones de mercado todo el tiempo, en todas las condiciones de mercado en algún momento del tiempo, pero nunca en todas las condiciones de mercado todo el tiempo."
Saylarr
Mensajes: 5
Registrado: 27 May 2021 07:06

Re: Duda Wilders Average

Mensaje por Saylarr »

lo necesito para hacer otro indicador jajaja la idea es usar este como funcion dentro del otro, pero si el repintado no es problema porque el otro indicador y la estrategia estan basados en elliot
Si te ha gustado este hilo del Foro, ¡compártelo en redes!


Responder

Volver a “Pine Script”