ProRealCode - Trading & Coding with ProRealTime™
Hola a tod@s. Puede alguien transcribir el siguiente indicador de Tradingview a PRT?:
https://es.tradingview.com/v/b7o7GmWT/
Cycle1(i, waveThrottle, cycs) =>
ret = 6.0*waveThrottle+1.0
if (i==0)
ret := 1.0+waveThrottle
else if (i==1)
ret := 1.0+waveThrottle*5.0
else if (i==(cycs-1))
ret := 1.0+waveThrottle
else if (i==(cycs-2))
ret := 1.0+waveThrottle*5.0
ret
Cycle2(i, waveThrottle, cycs) =>
ret=-4.0*waveThrottle
if (i==0)
ret := -2.0*waveThrottle
else if (i==(cycs-1))
ret := 0.0
else if (i==(cycs-2))
ret := -2.0*waveThrottle
ret
Cycle3(i, waveThrottle, cycs) =>
ret = waveThrottle
if (i==(cycs-1))
ret := 0.0
else if (i==(cycs-2))
ret := 0.0
ret
iWTT_CSI_processor(CycleCount) =>
wtt1=0.0
wtt2=0.0
wtt3=0.0
wtt4=0.0
wtt5=0.0
_wtt1=0.0
_wtt2=0.0
_wtt3=0.0
_wtt4=0.0
_wtt5=0.0
momentum=0.0
acceleration=0.0
swing=0.0
cycs=50
waveThrottle=float(160*CycleCount)
currentVal=0.0
for i = 0 to cycs – 1 by 1
swing:=Cycle1(i,waveThrottle,cycs)-wtt4*wtt1-_wtt5*_wtt2
if(swing==0)
break
momentum := Cycle2(i,waveThrottle,cycs)
_wtt1 := wtt1
wtt1 := (momentum-wtt4*wtt2)/swing
acceleration:=Cycle3(i,waveThrottle,cycs)
_wtt2 := wtt2
wtt2 := acceleration/swing
currentVal:=(close[49-i]-_wtt3*_wtt5-wtt3*wtt4)/swing
_wtt3 := wtt3
wtt3 := currentVal
wtt4 := momentum-wtt5*_wtt1
_wtt5 := wtt5
wtt5 := acceleration
currentVal
banding(CRSI, Period, Leveling) =>
var percent = Leveling / 100.0
periodMinusOne = Period-1
maxima = -999999.0
minima = 999999.0
for i=0 to periodMinusOne
crsi = nz(CRSI[i])
if crsi > maxima
maxima := crsi
else if crsi < minima
minima := crsi
stepFactor = (maxima – minima) / 100.0
float lowBand = na
for steps=0 to 100
testValue = minima + stepFactor * steps
below = 0
for m=0 to periodMinusOne
if CRSI[m] < testValue
below := below + 1
if below/Period >= percent
lowBand := testValue
break
float highBand = na
for steps=0 to 100
testValue = maxima – stepFactor * steps
above = 0
for m=0 to periodMinusOne
if CRSI[m] >= testValue
above := above + 1
if above/Period >= percent
highBand := testValue
break
[highBand, lowBand]
//==== Vars
var leveling = 10
var cyclicMemory = 34
//===== Calculations
thrust1=iWTT_CSI_processor(1)
thrust2=iWTT_CSI_processor(10)
CSIBuffer = thrust1-thrust2
[highBand, lowBand] = banding( CSIBuffer, cyclicMemory, leveling)
highband = plot(highBand, “HighBand”, color=color.aqua , editable=false)
lowband = plot( lowBand, “LowBand”, color=color.aqua , editable=false)
fill( highband, lowband, transp=90 , color=#CCCC77 )
plot(0, color=color.black, linewidth=1, transp=25)
plot(CSIBuffer, color=color.fuchsia, linewidth=1)
//------------------------------------------------------------//
//PRC_Cycle swing momentum
//version = 0
//11.06.24
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//------------------------------------------------------------//
//-----Inputs-------------------------------------------------//
leveling = 10
cyclicmemory = 34
//------------------------------------------------------------//
//-----Thrust1 Calculation------------------------------------//
CycleCount = 1
wtt1=0.0
wtt2=0.0
wtt3=0.0
wtt4=0.0
wtt5=0.0
pwtt1=0.0
pwtt2=0.0
pwtt3=0.0
pwtt4=0.0
pwtt5=0.0
mom=0.0
acceleration=0.0
swing=0.0
cycs=50
waveThrottle=(160*CycleCount)
currentVal=0.0
ret1=0
ret2=0
ret3=0
for i = 0 to cycs - 1 do
//Cycle1(i,waveThrottle,cycs)
ret1 = 6.0*waveThrottle+1.0
if i = 0 then
ret1 = 1+waveThrottle
elsif i=1 then
ret1 = 1+waveThrottle*5
elsif i=cycs-1 then
ret1 = 1+waveThrottle
elsif i=cycs-2 then
ret1 = 1+waveThrottle*5
endif
swing = ret1-wtt4*wtt1-pwtt5*pwtt2
if swing = 0 then
break
endif
//Cycle2(i, waveThrottle, cycs)
ret2 = -4.0*waveThrottle
if i=0 then
ret2 = -2.0*waveThrottle
elsif i=(cycs-1)then
ret2 = 0.0
elsif i=(cycs-2) then
ret2 = -2.0*waveThrottle
endif
mom=ret2
pwtt1=wtt1
wtt1=(mom-wtt4*wtt2)/swing
//Cycle3(i, waveThrottle, cycs)
ret3 = waveThrottle
if i=cycs-1 then
ret3 = 0
elsif i=cycs-2 then
ret3 = 0
endif
acceleration=ret3
pwtt2=wtt2
wtt2=acceleration/swing
currentval = (close[49-i]-pwtt3*pwtt5-wtt3*wtt4)/swing
pwtt3=wtt3
wtt3=currentval
wtt4=mom-wtt5*pwtt1
pwtt5=wtt5
wtt5=acceleration
next
thrust1 = currentval
/////thrust2
CycleCount2 = 10
wtt12=0.0
wtt22=0.0
wtt32=0.0
wtt42=0.0
wtt52=0.0
pwtt12=0.0
pwtt22=0.0
pwtt32=0.0
pwtt42=0.0
pwtt52=0.0
mom2=0.0
acceleration2=0.0
swing2=0.0
cycs2=50
waveThrottle2=(160*CycleCount2)
currentVal2=0.0
for j = 0 to cycs2 - 1 do
//Cycle1(i,waveThrottle,cycs)
ret12 = 6.0*waveThrottle2+1.0
if j = 0 then
ret12 = 1+waveThrottle2
elsif j=1 then
ret12 = 1+waveThrottle2*5
elsif j=cycs2-1 then
ret12 = 1+waveThrottle2
elsif j=cycs2-2 then
ret12 = 1+waveThrottle2*5
endif
swing2 = ret12-wtt42*wtt12-pwtt52*pwtt22
if swing2 =0 then
break
endif
//Cycle2(i, waveThrottle, cycs)
ret22 = -4.0*waveThrottle2
if j=0 then
ret22 = -2.0*waveThrottle2
elsif j=(cycs2-1)then
ret22 = 0.0
elsif j=(cycs2-2) then
ret22 = -2.0*waveThrottle2
endif
mom2=ret22
pwtt12=wtt12
wtt12=(mom2-wtt42*wtt22)/swing2
//Cycle3(i, waveThrottle, cycs)
ret32 = waveThrottle2
if j=cycs2-1 then
ret32 = 0
elsif j=cycs2-2 then
ret32 = 0
endif
acceleration2=ret32
pwtt22=wtt22
wtt22=acceleration2/swing2
currentval2 = (close[49-j]-pwtt32*pwtt52-wtt32*wtt42)/swing2
pwtt32=wtt32
wtt32=currentval2
wtt42=mom2-wtt52*pwtt12
pwtt52=wtt52
wtt52=acceleration2
next
thrust2=currentval2
CSIBuffer = thrust1-thrust2
//banding(CRSI, Period, Leveling)
//banding(CSIBuffer,cyclicMemory,leveling)
CRSI=CSIBuffer
Period=cyclicMemory
percent = leveling/100
periodMinusone = period-1
maxima = -999999.0
minima = 999999.0
for i=0 to periodMinusone do
//crsi = crsi[i]
if crsi[i] > maxima then
maxima = crsi[i]
elsif crsi[i] < minima then
minima = crsi[i]
endif
next
stepfactor = (maxima-minima)/100
lowband = 0
for steps=0 to 100 do
testvalue = minima+stepfactor*steps
below=0
for m=0 to periodMinusone do
if crsi[m]<testvalue then
below=below+1
endif
next
if below/period >= percent then
lowband = testvalue
break
endif
next
highband=0
for steps=0 to 100 do
testvalue=maxima-stepfactor*steps
above=0
for m=0 to periodMinusone do
if crsi[m]>=testvalue then
above=above+1
endif
next
if above/Period >= percent then
highband=testvalue
break
endif
next
colorbetween(highband,lowband,204,204,119,90)
return CSIBuffer as "CSIBuffer" coloured(224,64,251)style(line,2), Lowband as "Lowband" coloured(0,188,212),highband as "Highband" coloured(0,188,212), 0 coloured("black")
Más vale tarde que nunca. Aquí está el indicador completo.
Lo malo es que tarda mucho en cargar porque muy pesado de calculo…
//---------------------------------------------
// PRC_Cycle swing momentum
// Based on "Decoding The Hidden Market Rhythm" by Lars von Thienen
// version = 1
// 23.02.26
// Iván González @ www.prorealcode.com
// Sharing ProRealTime knowledge
//---------------------------------------------
// === PARAMETERS ===
//---------------------------------------------
src = close
showDiv = 1
showBands = 1
// Divergence parameters
plotBull = 1
plotHBull = 1
plotBear = 1
plotHBear = 1
lbR = 5
lbL = 5
rangeUp = 60
rangeLow = 5
// Band parameters
bandLevel = 10
bandPeriod = 34
// ================================================================
// CSI PROCESSOR - THRUST 1 (CycleCount = 1, waveThrottle = 160)
// ================================================================
cycs = 50
waveT = 160.0
w1 = 0.0
w2 = 0.0
w3 = 0.0
w4 = 0.0
w5 = 0.0
pw1 = 0.0
pw2 = 0.0
pw3 = 0.0
pw5 = 0.0
cVal = 0.0
brkFlag = 0
FOR i = 0 TO cycs - 1 DO
IF brkFlag = 0 THEN
// Cycle1 coefficient
c1 = 6.0 * waveT + 1.0
IF i = 0 THEN
c1 = 1.0 + waveT
ELSIF i = 1 THEN
c1 = 1.0 + waveT * 5.0
ELSIF i = cycs - 1 THEN
c1 = 1.0 + waveT
ELSIF i = cycs - 2 THEN
c1 = 1.0 + waveT * 5.0
ENDIF
swng = c1 - w4 * w1 - pw5 * pw2
IF swng = 0 THEN
brkFlag = 1
ELSE
// Cycle2 coefficient
c2 = -4.0 * waveT
IF i = 0 THEN
c2 = -2.0 * waveT
ELSIF i = cycs - 1 THEN
c2 = 0.0
ELSIF i = cycs - 2 THEN
c2 = -2.0 * waveT
ENDIF
pw1 = w1
w1 = (c2 - w4 * w2) / swng
// Cycle3 coefficient
c3 = waveT
IF i = cycs - 1 THEN
c3 = 0.0
ELSIF i = cycs - 2 THEN
c3 = 0.0
ENDIF
pw2 = w2
w2 = c3 / swng
valUse = src[49 - i]
cVal = (valUse - pw3 * pw5 - w3 * w4) / swng
pw3 = w3
w3 = cVal
w4 = c2 - w5 * pw1
pw5 = w5
w5 = c3
ENDIF
ENDIF
NEXT
thrust1 = cVal
// ================================================================
// CSI PROCESSOR - THRUST 2 (CycleCount = 10, waveThrottle = 1600)
// ================================================================
waveT = 1600.0
w1 = 0.0
w2 = 0.0
w3 = 0.0
w4 = 0.0
w5 = 0.0
pw1 = 0.0
pw2 = 0.0
pw3 = 0.0
pw5 = 0.0
cVal = 0.0
brkFlag = 0
FOR i = 0 TO cycs - 1 DO
IF brkFlag = 0 THEN
c1 = 6.0 * waveT + 1.0
IF i = 0 THEN
c1 = 1.0 + waveT
ELSIF i = 1 THEN
c1 = 1.0 + waveT * 5.0
ELSIF i = cycs - 1 THEN
c1 = 1.0 + waveT
ELSIF i = cycs - 2 THEN
c1 = 1.0 + waveT * 5.0
ENDIF
swng = c1 - w4 * w1 - pw5 * pw2
IF swng = 0 THEN
brkFlag = 1
ELSE
c2 = -4.0 * waveT
IF i = 0 THEN
c2 = -2.0 * waveT
ELSIF i = cycs - 1 THEN
c2 = 0.0
ELSIF i = cycs - 2 THEN
c2 = -2.0 * waveT
ENDIF
pw1 = w1
w1 = (c2 - w4 * w2) / swng
c3 = waveT
IF i = cycs - 1 THEN
c3 = 0.0
ELSIF i = cycs - 2 THEN
c3 = 0.0
ENDIF
pw2 = w2
w2 = c3 / swng
valUse = src[49 - i]
cVal = (valUse - pw3 * pw5 - w3 * w4) / swng
pw3 = w3
w3 = cVal
w4 = c2 - w5 * pw1
pw5 = w5
w5 = c3
ENDIF
ENDIF
NEXT
thrust2 = cVal
// ================================================================
// CSI BUFFER
// ================================================================
csiBuf = thrust1 - thrust2
// ================================================================
// DYNAMIC BANDS (optional)
// ================================================================
hBand = undefined
lBand = undefined
IF showBands = 1 AND barindex >= 84 THEN
pct = bandLevel / 100.0
bMax = -999999.0
bMin = 999999.0
FOR i = 0 TO bandPeriod - 1 DO
IF csiBuf[i] > bMax THEN
bMax = csiBuf[i]
ENDIF
IF csiBuf[i] < bMin THEN
bMin = csiBuf[i]
ENDIF
NEXT
stepF = (bMax - bMin) / 100.0
// Low band (percentile)
lbDone = 0
FOR s = 0 TO 100 DO
IF lbDone = 0 THEN
testVal = bMin + stepF * s
below = 0
FOR m = 0 TO bandPeriod - 1 DO
IF csiBuf[m] < testVal THEN
below = below + 1
ENDIF
NEXT
IF below / bandPeriod >= pct THEN
lBand = testVal
lbDone = 1
ENDIF
ENDIF
NEXT
// High band (percentile)
hbDone = 0
FOR s = 0 TO 100 DO
IF hbDone = 0 THEN
testVal = bMax - stepF * s
above = 0
FOR m = 0 TO bandPeriod - 1 DO
IF csiBuf[m] >= testVal THEN
above = above + 1
ENDIF
NEXT
IF above / bandPeriod >= pct THEN
hBand = testVal
hbDone = 1
ENDIF
ENDIF
NEXT
ENDIF
// ================================================================
// DIVERGENCE DETECTION (optional)
// ================================================================
osc = csiBuf
totalLB = lbL + lbR + 1
// Pivot detection
plFound = 0
phFound = 0
IF showDiv = 1 AND barindex >= totalLB THEN
IF osc[lbR] <= lowest[totalLB](osc) THEN
plFound = 1
ENDIF
IF osc[lbR] >= highest[totalLB](osc) THEN
phFound = 1
ENDIF
ENDIF
// Pivot low tracking (valuewhen + barssince emulation)
once lastPLOsc = -999999.0
once lastPLPrc = -999999.0
once plCount = 0
once barsSincePL = 999
// Pivot high tracking
once lastPHOsc = 999999.0
once lastPHPrc = 999999.0
once phCount = 0
once barsSincePH = 999
bullCond = 0
hBullCond = 0
bearCond = 0
hBearCond = 0
// --- Pivot Low divergences ---
IF plFound = 1 THEN
plInRng = 0
IF barsSincePL >= rangeLow AND barsSincePL <= rangeUp THEN
plInRng = 1
ENDIF
IF plCount >= 1 AND plInRng = 1 THEN
// Regular Bullish: price lower low + osc higher low
IF plotBull = 1 AND low[lbR] < lastPLPrc AND osc[lbR] > lastPLOsc THEN
bullCond = 1
ENDIF
// Hidden Bullish: price higher low + osc lower low
IF plotHBull = 1 AND low[lbR] > lastPLPrc AND osc[lbR] < lastPLOsc THEN
hBullCond = 1
ENDIF
ENDIF
// Update state AFTER divergence check
lastPLOsc = osc[lbR]
lastPLPrc = low[lbR]
barsSincePL = 0
plCount = plCount + 1
ELSE
IF showDiv = 1 THEN
barsSincePL = barsSincePL + 1
ENDIF
ENDIF
// --- Pivot High divergences ---
IF phFound = 1 THEN
phInRng = 0
IF barsSincePH >= rangeLow AND barsSincePH <= rangeUp THEN
phInRng = 1
ENDIF
IF phCount >= 1 AND phInRng = 1 THEN
// Regular Bearish: price higher high + osc lower high
IF plotBear = 1 AND high[lbR] > lastPHPrc AND osc[lbR] < lastPHOsc THEN
bearCond = 1
ENDIF
// Hidden Bearish: price lower high + osc higher high
IF plotHBear = 1 AND high[lbR] < lastPHPrc AND osc[lbR] > lastPHOsc THEN
hBearCond = 1
ENDIF
ENDIF
// Update state AFTER divergence check
lastPHOsc = osc[lbR]
lastPHPrc = high[lbR]
barsSincePH = 0
phCount = phCount + 1
ELSE
IF showDiv = 1 THEN
barsSincePH = barsSincePH + 1
ENDIF
ENDIF
// ================================================================
// COLOR CALCULATIONS
// ================================================================
// Area fill: green/red with momentum-based alpha
IF csiBuf >= 0 THEN
aR = 0
aG = 153
aB = 136
IF csiBuf > csiBuf[1] THEN
aAlpha = 102
ELSE
aAlpha = 77
ENDIF
ELSE
aR = 204
aG = 51
aB = 17
IF csiBuf < csiBuf[1] THEN
aAlpha = 102
ELSE
aAlpha = 77
ENDIF
ENDIF
// CSI main line color
IF csiBuf >= 0 THEN
cR = 0
cG = 153
cB = 136
ELSE
cR = 204
cG = 51
cB = 17
ENDIF
// Band fill alpha
IF showBands = 1 THEN
bfAlpha = 13
ELSE
bfAlpha = 0
ENDIF
// ================================================================
// DRAW DIVERGENCE SIGNALS
// ================================================================
IF bullCond = 1 THEN
DRAWPOINT(barindex - lbR, csiBuf[lbR], 3) coloured(0, 153, 136)
ENDIF
IF hBullCond = 1 THEN
DRAWPOINT(barindex - lbR, csiBuf[lbR], 2) coloured(0, 200, 170)
ENDIF
IF bearCond = 1 THEN
DRAWPOINT(barindex - lbR, csiBuf[lbR], 3) coloured(204, 51, 17)
ENDIF
IF hBearCond = 1 THEN
DRAWPOINT(barindex - lbR, csiBuf[lbR], 2) coloured(220, 100, 70)
ENDIF
// ================================================================
// COLOR FILLS (always OUTSIDE conditionals)
// ================================================================
zeroRef = 0
COLORBETWEEN(csiBuf, zeroRef, aR, aG, aB, aAlpha)
COLORBETWEEN(hBand, lBand, 212, 166, 0, bfAlpha)
// ================================================================
// RETURN (always last line)
// ================================================================
RETURN csiBuf coloured(cR, cG, cB) style(line, 2) AS "CSI", zeroRef coloured(0, 0, 0) style(line, 1) AS "Zero", hBand coloured(59, 111, 202) AS "High Band", lBand coloured(59, 111, 202) AS "Low Band"
This topic contains 2 replies,
has 2 voices, and was last updated by
Iván González
1 week, 1 day ago.
| Forum: | TradingView to ProRealTime Translation Center Forum |
| Started: | 02/21/2024 |
| Status: | Active |
| Attachments: | 1 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.