Convert Market Structure RSI code to PRO REAL TIME PLEASE
Forums › ProRealTime English forum › ProBuilder support › Convert Market Structure RSI code to PRO REAL TIME PLEASE
- This topic has 2 replies, 2 voices, and was last updated 6 months ago by yas.
-
-
05/24/2024 at 3:16 PM #233022
hi Ivan if you can convert this code below to pro real time please
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ClayeWeight//@version=5
indicator(“Market Structure RSI”)rsiLength = input.int(20, “RSI Length”, minval = 1, group=”Market Structure RSI”)
OBlvl = input.int(80, “Overbought Level”, minval = 1, maxval=100, group=”Market Structure RSI”)
OSlvl = input.int(20, “Oversold Level”, minval = 1, maxval=100, group=”Market Structure RSI”)strCloseType = input.string(“High/Low”, “Close Type”, [“Close”, “High/Low”], tooltip=”Choose whether the structure is deemed broken with either a Close or the Candle High/Low”, group=”Market Structure RSI”)
closeTypeBull = strCloseType == “Close” ? close[1] : high[1]
closeTypeBear = strCloseType == “Close” ? close[1] : low[1]maBool = input.bool(true, “Show Moving Average”, group=”Moving Average”)
maSelection = input.string(“EMA”, “MA Type”, [“EMA”, “SMA”, “WMA”], group=”Moving Average”)
maLength = input.int(8, “MA Length”, minval = 1, group=”Moving Average”)// Get Pivots
pH = high[3] < high[2] and high[2] > high[1]
pL = low[3] > low[2] and low[2] < low[1]var highPrice = array.new_float()
var lowPrice = array.new_float()
var count = array.new_int()if pH
highPrice.push(high[2])
if pL
lowPrice.push(low[2])add_to_total(dir, priceArray, countArray, closeType, add) =>
if array.size(priceArray) > 0
for l = array.size(priceArray)-1 to 0
if (dir == 1 and closeType > array.get(priceArray, l)) or (dir == 0 and closeType < array.get(priceArray, l))
array.remove(priceArray, l)
array.push(countArray, add)
else
breakadd_to_total(1, highPrice, count, closeTypeBull, 1)
add_to_total(0, lowPrice, count, closeTypeBear, -1)// Get Total
total = array.sum(count)
rsiTotal = ta.rsi(total, rsiLength)float rsmMATotal = switch maSelection
“EMA” => ta.ema(rsiTotal, maLength)
“SMA” => ta.sma(rsiTotal, maLength)
“WMA” => ta.wma(rsiTotal, maLength)// Plot RSI
rsiPlot = plot(rsiTotal, color=na, linewidth = 2, title= “RSI Line”, editable = false)
plot(maBool ? rsmMATotal : na, color=#0075ff, title= “RSI Moving Average”, linewidth = 2)// Plot Signals
structureOB = ta.crossunder(rsiTotal, OBlvl)
structureOS = ta.crossover(rsiTotal, OSlvl)
plotshape(structureOB ? OBlvl : na, size = size.tiny, style = shape.circle, location = location.absolute, color = color.red, title = “Bearish Signal”)
plotshape(structureOS ? OSlvl : na, size = size.tiny, style = shape.circle, location = location.absolute, color = color.green, title = “Bullish Signal”)// Plot High and Low lines
hline(OBlvl, title = “Overbought Level”)
hline(OSlvl, title = “Oversold Level”)// Gradient Fill
midPlot = plot(50, color=rsiTotal>50?color.lime:color.red) //, color = na, editable = false, display = display.none)
fill(rsiPlot, midPlot, 150, 50, top_color = color.new(color.lime, 0), bottom_color = color.new(color.lime, 100), title = “Overbought Gradient Fill”)
fill(rsiPlot, midPlot, 50, -50, top_color = color.new(color.red, 100), bottom_color = color.new(color.red, 0), title = “Oversold Gradient Fill”)// Alerts
alertcondition(structureOB, “Bearish Signal”, “Structure RSI is crossing under the Overbought level”)
alertcondition(structureOS, “Bullish Signal”, “Structure RSI is crossing over the Oversold level”)05/27/2024 at 12:54 PM #233086Hi!
Here is the code:123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106//------------------------------------------------------------////PRC_Market Structure RSI//version = 0//27.05.24//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge//------------------------------------------------------------////-----Inputs-------------------------------------------------//rsiLength=20OBlvl=80OSlvl=20strCloseType=0maBool=1maSelection=1maLength=8color=1signals=0//------------------------------------------------------------////-----Close Type---------------------------------------------//if strCloseType thencloseTypeBull=close[1]closeTypeBear=close[1]elsecloseTypeBull=high[1]closeTypeBear=low[1]endif//-----Get Pivots---------------------------------------------//pH=high[3]<high[2] and high[2]>high[1]pL=low[3]>low[2] and low[2]<low[1]if pH then$highprice[z+1]=high[2]$highidx[z+1]=barindex[2]z=z+1endifif pL then$lowprice[t+1]=low[2]$lowidx[t+1]=barindex[2]t=t+1endif//------------------------------------------------------------////-----Get Source for RSI calculation-------------------------//$count[0]=0if isset($highprice[z]) thenfor i=z downto 0 doif closeTypeBull>$highprice[i] then$highprice[i]=exp(10)$count[r+1]=$count[r]+1r=r+1elsebreakendifnextendifif isset($lowprice[t]) thenfor j=t downto 0 doif closeTypeBear<$lowprice[j] then$lowprice[j]=0$count[r+1]=$count[r]-1r=r+1elsebreakendifnextendif//------------------------------------------------------------////-----Get total array count----------------------------------//total=0for k=0 to r dototal=total+$count[r]next//------------------------------------------------------------////-----RSI total----------------------------------------------//rsitotal=rsi[rsilength](total)//------------------------------------------------------------////-----RSI Moving Average-------------------------------------//if maBool thenrsmMATotal=average[maLength,maSelection](rsitotal)elsersmMATotal=undefinedendif//------------------------------------------------------------////-----Plot configuration-------------------------------------//if color thenif rsitotal > 50 thenrc=0gc=255elserc=255gc=0endifcolorbetween(rsitotal,50,rc,gc,0,50)endif//------------------------------------------------------------////-----Draw Signals-------------------------------------------//if signals thenif rsiTotal crosses under OBlvl thendrawpoint(barindex,OBlvl,2)coloured("red")elsif rsiTotal crosses over OSlvl thendrawpoint(barindex,OSlvl,2)coloured("green")endifendif//------------------------------------------------------------//return rsitotal, rsmMATotal coloured("blue")style(line,4), OBlvl as "Overbought Level"style(dottedline2), OSlvl as "Oversold level"style(dottedline2)1 user thanked author for this post.
05/27/2024 at 2:01 PM #233092 -
AuthorPosts
Find exclusive trading pro-tools on