4CMACDSqueeze
Forums › ProRealTime foro Español › Soporte ProBuilder › 4CMACDSqueeze
- This topic has 3 replies, 2 voices, and was last updated 7 years ago by Nicolas.
-
-
06/20/2017 at 10:46 AM #38629
Buenos días.Estoy intentando pasar a Prorealtime este código de la plataforma Tradingview : https://es.tradingview.com/script/hzOZZ1dU-4CMACDSqueeze/
El problema lo tengo al intentar poner los colores del histograma del macd. Solo he podido poner dos colores correctamente,celeste y gris en la parte superior del macd.
¿Alguien puede ayudar para sacar el código lo más posiblemente similar al del original?
Aquí la parte de código que llevo traducida :
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192REM 4CMACDSqueeze//@version=3//study("4CMACDSqueeze"//===============macd================//source = closefastLength = 12slowLength=26signalLength=9fastMA =ExponentialAverage[fastLength](source)slowMA =ExponentialAverage[slowLength](source)macdd = fastMA - slowMAsignal =Average [signalLength](macdd)outMacD = macddoutSignal = signal//=========================4CHistogram===================//currMacd = MACD[fastLength,slowLength,9](close[0])prevMacd = MACD[fastLength,slowLength,9](close[1])if currMacd >0 thenif currMacd >prevMacd thenr=0g=191b=255elser=204g=204b=204endifendif//========================Squeeze==================//length = 20 //title="Bollinger Band Length"lengthKC=20 //title="Keltner Channel Length"multKC =1.5 //title="KC Deviations"//useTrueRange =true title="Use TrueRange (KC)", type=bool)// Calculate BBbasis =Average [length](source)dev = multKC *STD[length](source)upperBB = basis + devlowerBB = basis - dev// Calculate KCma = Average [lengthKC](source)rango=useTrueRangeif rango = useTrueRange thenuseTrueRange=TR(close)elseuseTrueRange=(high - low)endifrangema =Average[lengthKC](rango)upperKC = ma + rangema * multKClowerKC = ma - rangema * multKCsqzOn = (lowerBB > lowerKC) and (upperBB < upperKC)sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)noSqz = sqzOn and sqzOffval =LinearRegression(source) - (highest[lengthKC]( high)and lowest[lengthKC] (low))and Average [lengthKC](close) and lengthKC and 0if noSqz thensr=0sg=0sb=0elsif sqzOn thensr=0sg=0sb=0elsesr=128sg=0sb=128endifreturn outmacd coloured (0,191,255)style(line,2)as "macd line",outmacd coloured(r,g,b)style (histogram)as "Macd", val coloured (sr,sg,sb)style(line,3) as "0",outsignal coloured(255,153,51)style (line,2)as "signal"06/20/2017 at 11:36 AM #38637He modificado el código un poco. Creo que ha cometido algunos errores entre lo que es y cómo se calcula un histograma MACD en tradingview y prorealtime. Hay algo diferente. Espero que no haya ningún error en mi código aunque 🙂 Por favor, hágamelo saber!
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697REM 4CMACDSqueeze//@version=3//study("4CMACDSqueeze"//===============macd================//source = closefastLength = 12slowLength=26signalLength=9fastMA =ExponentialAverage[fastLength](source)slowMA =ExponentialAverage[slowLength](source)macdd = fastMA - slowMAsignal =Average [signalLength](macdd)outMacD = macddoutSignal = signal//=========================4CHistogram===================////currMacd = MACD[fastLength,slowLength,9](close[0])//prevMacd = MACD[fastLength,slowLength,9](close[1])if outMACD <0 thenif outMACD <outMACD[1] thenr = 240g = 128b = 128elser=204g=204b=204endifelsif outMACD >0 thenif outMACD >outMACD[1] thenr=0g=191b=255elser=204g=204b=204endifendif//========================Squeeze==================//length = 20 //title="Bollinger Band Length"lengthKC=20 //title="Keltner Channel Length"multKC =1.5 //title="KC Deviations"//useTrueRange =true title="Use TrueRange (KC)", type=bool)// Calculate BBbasis =Average [length](source)dev = multKC *STD[length](source)upperBB = basis + devlowerBB = basis - dev// Calculate KCma = Average [lengthKC](source)rango=useTrueRangeif rango = useTrueRange thenuseTrueRange=TR(close)elseuseTrueRange=(high - low)endifrangema =Average[lengthKC](rango)upperKC = ma + rangema * multKClowerKC = ma - rangema * multKCsqzOn = (lowerBB > lowerKC) and (upperBB < upperKC)sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)noSqz = sqzOn and sqzOffval =LinearRegression(source) - (highest[lengthKC]( high)and lowest[lengthKC] (low))and Average [lengthKC](close) and lengthKC and 0if noSqz thensr=0sg=0sb=0elsif sqzOn thensr=0sg=0sb=0elsesr=128sg=0sb=128endifreturn outmacd coloured(r,g,b)style (histogram,1)as "Macd", val coloured (sr,sg,sb)style(line,3) as "0",outsignal coloured(255,153,51)style (line,2)as "signal"1 user thanked author for this post.
06/20/2017 at 12:14 PM #38644Es correcto, le quedo eternamente agradecido.Otro indicador más para la biblioteca de Prorealcode. ¿ lo subirá?
06/20/2017 at 1:00 PM #38647Sí, por favor, publícalo con alguna explicación y lo revisaré para publicarlo públicamente. Gracias por tu trabajo 🙂
1 user thanked author for this post.
-
AuthorPosts