Percentile Code Error

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #253169 quote
    BardBard
    Participant
    Master
    Hi, I was wondering if anyone can get this Percentile code to work: VolRank = Percentile[60](Volume, 75) // 75th percentile of past 60 bars I tried many iterations but i am not sure why it won’t work? Also what happened to the add code icon? Cheers!

    // ============================================================

    // Strategy: bearish_engulf_MA20_25pct

    // Description: Short on bearish engulfing below MA20 with volume filter

    // ============================================================

    // — Parameters

    DEFPARAM CumulateOrders = False

    DEFPARAM PreLoadBars = 60

    StopPercent = 2.0 // change to 1.0, 3.0, etc. as needed

    Capital = 1000

    // — Indicators

    MA20 = Average[20](Close)

    VolRank = Percentile[60](Volume, 75) // 75th percentile of past 60 bars

    // — Bearish Engulfing detection

    BearishEngulf = (Close[1] > Open[1]) AND (Close < Open) AND (Open > Close[1]) AND (Close < Open[1])

    // — Entry condition

    ShortCondition = BearishEngulf AND (Close < MA20) AND (Volume > VolRank)

    // — Position management

    If ShortCondition THEN

    SellShort 1 CONTRACT AT MARKET

    ENDIF

    // — Stop-loss in price terms

    If ShortOnMarket THEN

    EntryPrice = ShortPrice

    StopPrice = EntryPrice * (1 + StopPercent / 100)

    SET STOP pLOSS (StopPercent * Capital / 100)

    ENDIF

    // — Exit end-of-day (if not stopped)

    If ShortOnMarket AND BarIndex > TradeIndex THEN

    ExitShort AT Close

    ENDIF

    #253177 quote
    GraHalGraHal
    Participant
    Master
    what happened to the add code icon?
    If we press Ctrl + F5 (clear cache for PRC website only) before we start typing then you should see the blue  ‘Insert PRT Code’ icon at the far right of the top toolbar? Trick is remembering to Ctrl + F5 BEFORE typing anything at all! If you Ctrl + F5 after typing then you lose whatever you just typed!
    Iván González and Bard thanked this post
    #253178 quote
    JSJS
    Participant
    Master
    Hi, You use “Percentile[60](Volume,75)” as an indicator, but this indicator does not exist (by default) in PRT… You will first have to calculate the “Percentile” yourself…
    robertogozzi and Iván González thanked this post
    #253207 quote
    Iván GonzálezIván González
    Moderator
    Legend
    Hi. Here you have an example of percentile calculation:
    //Percentile
    p=252
    rnkCount = 0
    count = 0
    FOR i = 1 to p-1
    count = count + 1
    IF close[i] < close THEN
    rnkCount = rnkCount + 1
    endif
    NEXT
     
    PercentileRank = (rnkCount/count)*100
    
    drawhline(10)style(dottedline)
    drawhline(20)style(dottedline,2)
    drawhline(30)style(dottedline)
    drawhline(40)style(dottedline,2)
    drawhline(50)style(dottedline1)coloured("red")
    drawhline(60)style(dottedline,2)
    drawhline(70)style(dottedline)
    drawhline(80)style(dottedline,2)
    drawhline(90)style(dottedline)
    return PercentileRank
    
    robertogozzi and Bard thanked this post
    #253249 quote
    BardBard
    Participant
    Master
    Cheers Iván!
Viewing 5 posts - 1 through 5 (of 5 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

Percentile Code Error


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Bard @brad Participant
Summary

This topic contains 4 replies,
has 4 voices, and was last updated by BardBard
10 months, 2 weeks ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/01/2025
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...