Buenas! Aquí lo tienes:
//--------------------------------------------------------//
//PRC_Market Structure Oscillator
//version = 0
//17.10.2024
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//--------------------------------------------------------//
//--------------------Inputs------------------------------//
//--------------------------------------------------------//
msOscShow=1
cycleOpt=1
msDataK1=0 //short term oscillator
msDataK2=0 //intermediate term oscillator
msDataK3=0 //long term oscillator
NormSmooth=4
cycSmooth=7
msWeightk1=1
msWeightk2=3
msWeightk3=2
//--------------------------------------------------------//
//----------Calculations - Oscillator---------------------//
//--------------------------------------------------------//
if msOscShow or msDataK1 or msDataK2 or msDataK3 then
oscTop=100
upperband=85
midline=50
lowerband=15
oscBtm=0
else
oscTop=undefined
endif
//StValue1 = ShortMarketStructure
bull=0
bear=0
if high[2]<high[1] and high[1]>=high then
stHighprevPrice=stHighMidPrice
stHighMidPrice=stHighLastPrice
stHighLastPrice=high[1]
stHighprevIndex=stHighMidIndex
stHighMidIndex=stHighLastIndex
stHighLastIndex=barindex[1]
stHighIsCrossed=0
endif
if close>stHighLastPrice and stHighIsCrossed=0 then
stHighIsCrossed=1
bull=1
endif
if low[2]>low[1] and low[1]<=low then
stLowprevPrice=stLowMidPrice
stLowMidPrice=stLowLastPrice
stLowLastPrice=low[1]
stLowprevIndex=stLowMidIndex
stLowMidIndex=stLowLastIndex
stLowLastIndex=barindex[1]
stLowIsCrossed=0
endif
if close<stLowLastPrice and stLowIsCrossed=0 then
stLowIsCrossed=1
bear=1
endif
once os=0
once mimax=close
once mimin=close
if bull then
os=1
elsif bear then
os=-1
endif
if os>os[1] then
mimax=close
mimin=mimin
elsif os<os[1] then
mimax=mimax
mimin=close
else
mimax=max(close,mimax)
mimin=min(close,mimin)
endif
StValue1=100*average[NormSmooth]((close-mimin)/(mimax-mimin))
//StValue2 = MarketStructure (itHigh,itLow,stHigh,stLow)
bull2=0
bear2=0
cSwingHigh=stHighprevPrice<stHighMidPrice and stHighMidPrice>=stHighLastPrice
if cSwingHigh and cSwingHigh<>cSwingHigh[1] then
itHighprevPrice=itHighMidPrice
itHighMidPrice=itHighLastPrice
itHighLastPrice=stHighMidPrice
itHighprevIndex=itHighMidIndex
itHighMidIndex=itHighLastIndex
itHighLastIndex=stHighMidIndex
itHighIsCrossed=0
endif
if close>itHighLastPrice and itHighIsCrossed=0 then
itHighIsCrossed=1
bull2=1
endif
cSwingLow=stLowprevPrice>stLowMidPrice and stLowMidPrice<=stLowLastPrice
if cSwingLow and cSwingLow<>cSwingLow[1] then
itLowprevPrice=itLowMidPrice
itLowMidPrice=itLowLastPrice
itLowLastPrice=stLowMidPrice
itLowprevIndex=itLowMidIndex
itLowMidIndex=itLowLastIndex
itLowLastIndex=stLowMidIndex
itLowIsCrossed=0
endif
if close<itLowLastPrice and itLowIsCrossed=0 then
itLowIsCrossed=1
bear2=1
endif
once os2=0
once mimax2=close
once mimin2=close
if bull2 then
os2=1
elsif bear2 then
os2=-1
endif
if os2>os2[1] then
mimax2=close
mimin2=mimin2
elsif os2<os2[1] then
mimax2=mimax2
mimin2=close
else
mimax2=max(close,mimax2)
mimin2=min(close,mimin2)
endif
StValue2=100*average[NormSmooth]((close-mimin2)/(mimax2-mimin2))
//StValue3 = MarketStructure (ltHigh,ltLow,itHigh,itLow)
bull3=0
bear3=0
cSwingHigh3=itHighprevPrice<itHighMidPrice and itHighMidPrice>=itHighLastPrice
if cSwingHigh3 and cSwingHigh3<>cSwingHigh3[1] then
ltHighprevPrice=ltHighMidPrice
ltHighMidPrice=ltHighLastPrice
ltHighLastPrice=itHighMidPrice
ltHighprevIndex=ltHighMidIndex
ltHighMidIndex=ltHighLastIndex
ltHighLastIndex=itHighMidIndex
ltHighIsCrossed=0
endif
if close>ltHighLastPrice and ltHighIsCrossed=0 then
ltHighIsCrossed=1
bull3=1
endif
cSwingLow3=itLowprevPrice>itLowMidPrice and itLowMidPrice<=itLowLastPrice
if cSwingLow3 and cSwingLow3<>cSwingLow3[1] then
ltLowprevPrice=ltLowMidPrice
ltLowMidPrice=ltLowLastPrice
ltLowLastPrice=itLowMidPrice
ltLowprevIndex=ltLowMidIndex
ltLowMidIndex=ltLowLastIndex
ltLowLastIndex=itLowMidIndex
ltLowIsCrossed=0
endif
if close<ltLowLastPrice and ltLowIsCrossed=0 then
ltLowIsCrossed=1
bear3=1
endif
once os3=0
once mimax3=close
once mimin3=close
if bull3 then
os3=1
elsif bear3 then
os3=-1
endif
if os3>os3[1] then
mimax3=close
mimin3=mimin3
elsif os3<os3[1] then
mimax3=mimax3
mimin3=close
else
mimax3=max(close,mimax3)
mimin3=min(close,mimin3)
endif
StValue3=100*average[NormSmooth]((close-mimin3)/(mimax3-mimin3))
//--------------------------------------------------------//
//-----Oscillator line------------------------------------//
//--------------------------------------------------------//
msOsc=(msWeightk1*StValue1+msWeightk2*StValue2+msWeightk3*StValue3)/(msWeightk1+msWeightk2+msWeightk3)
//--------------------------------------------------------//
//-----Oscillator Histogram-------------------------------//
//--------------------------------------------------------//
if cycleOpt then
cyclefast=msOsc-average[cycSmooth,1](msOsc)+50
else
cyclefast=50
endif
if cyclefast>50 then
drawcandle(50,50,50,cyclefast)coloured(49,121,245)
elsif cyclefast<50 then
drawcandle(50,50,50,cyclefast)coloured(255,167,38)
endif
//--------------------------------------------------------//
//-----Short-Intermediate-Long Term Oscillator------------//
//--------------------------------------------------------//
if msDataK1 then
osc1=StValue1
else
osc1=undefined
endif
if msDataK2 then
osc2=StValue2
else
osc2=undefined
endif
if msDataK3 then
osc3=StValue3
else
osc3=undefined
endif
//--------------------------------------------------------//
colorbetween(oscTop,upperband,255,167,38,100)
colorbetween(oscBtm,lowerband,49,121,245,100)
//--------------------------------------------------------//
return oscTop as "Osc Top" coloured("grey",0),oscBtm as "Osc Bot" coloured("grey",0), upperband as "Overbought Level" coloured("grey",0), lowerband as "Oversold Level" coloured("grey",0), midline as "Equilibrium Level" coloured("black",100)style(dottedline), msOsc coloured("BLUE")style(line,2),osc1 as "Short Term" coloured("grey"),osc2 as "Intermediate Term" coloured("grey"),osc3 as "Long Term" coloured("grey")