10 biggest bars

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #245134 quote
    LuddeLudde
    Participant
    Junior

    I would appreciate help with an indicator under the following conditions.
    The indicator should display the 10 largest bars from the last 60 bars.
    The bars should be measured from the opening price to the closing price.
    If the bar is negative, it should display a blue arrow below the bar. If the bar is positive, it should display a yellow arrow below the bar.
    I would be grateful for your help.

    #245140 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    There you go:

    DEFPARAM DrawOnLastBarOnly = True
    ONCE P  = 60    //last 60 bars
    ONCE N  = 10    //10 largest bars within the last 60 bars
    Body    = abs(close - open)
    IF BarIndex > P THEN
    FOR i = 0 TO (P - 1)
    $LargestBody[i] = Body[i]
    $LargestBar[i]  = BarIndex[i]
    $Bull[i]        = 0
    $Bear[i]        = 0
    IF (close[i] > open[i]) THEN
    $Bull[i]     = 1
    ENDIF
    IF (close[i] < open[i]) THEN
    $Bear[i]     = 1
    ENDIF
    $xLow[i]        = low[i]
    $xRange[i]      = range[i]
    NEXT
    //////////////////////////////////////////////////////////////////
    // (Bubble Sort)
    FOR i = 0 TO (P - 1)
    FOR j = 0 TO (P - i - 1)
    IF $LargestBody[j] < $LargestBody[j + 1] THEN
    // swap data
    temp                = $LargestBody[j]
    $LargestBody[j]     = $LargestBody[j + 1]
    $LargestBody[j + 1] = temp
    // swap labels
    temp                = $LargestBar[j]
    $LargestBar[j]      = $LargestBar[j + 1]
    $LargestBar[j + 1]  = temp
    // swap Bullish status
    temp                = $Bull[j]
    $Bull[j]            = $Bull[j + 1]
    $Bull[j + 1]        = temp
    // swap Bearish status
    temp                = $Bear[j]
    $Bear[j]            = $Bear[j + 1]
    $Bear[j + 1]        = temp
    // swap LOWs
    temp                = $xLow[j]
    $xLow[j]            = $xLow[j + 1]
    $xLow[j + 1]        = temp
    // swap LOWs
    temp                = $xRange[j]
    $xRange[j]          = $xRange[j + 1]
    $xRange[j + 1]      = temp
    ENDIF
    NEXT
    NEXT
    //////////////////////////////////////////////////////////////////
    // plot Sorted arrays
    FOR i = 0 TO (N - 1)
    tempBAR   = $LargestBar[i]
    tempLOW   = $xLow[i]
    tempRANGE = $xRange[i]
    tempBODY  = $LargestBody[i]
    tempBULL  = $Bull[i]
    tempBEAR  = $Bear[i]
    IF tempBULL THEN
    DrawArrowUP(tempBAR,tempLOW - tempRANGE) coloured("Yellow")
    ELSIF tempBEAR THEN
    DrawArrowUP(tempBAR,tempLOW - tempRANGE) coloured("Blue")
    ENDIF
    //drawtext("#tempBAR#",barindex + 2,close * (1 + (0.002 * i)))
    //drawtext("#tempBODY#",barindex + 8,close * (1 + (0.002 * i)))
    //drawtext("#tempLOW#",barindex + 14,close * (1 + (0.002 * i)))
    //drawtext("#tempRANGE#",barindex + 20,close * (1 + (0.002 * i)))
    //drawtext("#tempBULL#",barindex + 26,close * (1 + (0.002 * i)))
    //drawtext("#tempBEAR#",barindex + 32,close * (1 + (0.002 * i)))
    NEXT
    ENDIF
    RETURN
    druby, Ludde and Iván González thanked this post
Viewing 2 posts - 1 through 2 (of 2 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

10 biggest bars


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Ludde @ludde Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by robertogozzirobertogozzi
1 year, 6 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 03/22/2025
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...