Convert Market Structure RSI code to PRO REAL TIME PLEASE

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #233022 quote
    yasyas
    Participant
    Junior

    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
    break

    add_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”)

    #233086 quote
    Iván GonzálezIván González
    Moderator
    Legend

    Hi!
    Here is the code:

    //------------------------------------------------------------//
    //PRC_Market Structure RSI
    //version = 0
    //27.05.24
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //------------------------------------------------------------//
    //-----Inputs-------------------------------------------------//
    rsiLength=20
    OBlvl=80
    OSlvl=20
    strCloseType=0
    maBool=1
    maSelection=1
    maLength=8
    color=1
    signals=0
    //------------------------------------------------------------//
    //-----Close Type---------------------------------------------//
    if strCloseType then
    closeTypeBull=close[1]
    closeTypeBear=close[1]
    else
    closeTypeBull=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+1
    endif
    
    if pL then
    $lowprice[t+1]=low[2]
    $lowidx[t+1]=barindex[2]
    t=t+1
    endif
    //------------------------------------------------------------//
    //-----Get Source for RSI calculation-------------------------//
    $count[0]=0
    if isset($highprice[z]) then
    for i=z downto 0 do
    if closeTypeBull>$highprice[i] then
    $highprice[i]=exp(10)
    $count[r+1]=$count[r]+1
    r=r+1
    else
    break
    endif
    next
    endif
    
    if isset($lowprice[t]) then
    for j=t downto 0 do
    if closeTypeBear<$lowprice[j] then
    $lowprice[j]=0
    $count[r+1]=$count[r]-1
    r=r+1
    else
    break
    endif
    next
    endif
    //------------------------------------------------------------//
    //-----Get total array count----------------------------------//
    total=0
    for k=0 to r do
    total=total+$count[r]
    next
    //------------------------------------------------------------//
    //-----RSI total----------------------------------------------//
    rsitotal=rsi[rsilength](total)
    //------------------------------------------------------------//
    //-----RSI Moving Average-------------------------------------//
    if maBool then
    rsmMATotal=average[maLength,maSelection](rsitotal)
    else
    rsmMATotal=undefined
    endif
    //------------------------------------------------------------//
    //-----Plot configuration-------------------------------------//
    if color then
    if rsitotal > 50 then
    rc=0
    gc=255
    else
    rc=255
    gc=0
    endif
    colorbetween(rsitotal,50,rc,gc,0,50)
    endif
    //------------------------------------------------------------//
    //-----Draw Signals-------------------------------------------//
    if signals then
    if rsiTotal crosses under OBlvl then
    drawpoint(barindex,OBlvl,2)coloured("red")
    elsif rsiTotal crosses over OSlvl then
    drawpoint(barindex,OSlvl,2)coloured("green")
    endif
    endif
    //------------------------------------------------------------//
    return rsitotal, rsmMATotal coloured("blue")style(line,4), OBlvl as "Overbought Level"style(dottedline2), OSlvl as "Oversold level"style(dottedline2)
    
    JS thanked this post
    #233092 quote
    yasyas
    Participant
    Junior

    Thanks Ivan much appreciated thanks again

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Convert Market Structure RSI code to PRO REAL TIME PLEASE


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
yas @yas Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by yasyas
2 years, 3 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 05/24/2024
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...