Percentile Code Error
Forums › ProRealTime English forum › ProOrder support › Percentile Code Error
- This topic has 3 replies, 4 voices, and was last updated 4 hours ago by
Iván.
-
-
11/01/2025 at 10:25 AM #253169
Hi, I was wondering if anyone can get this Percentile code to work:
VolRank = Percentile[60](Volume, 75) // 75th percentile of past 60 barsI 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
11/01/2025 at 12:12 PM #253177what 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!
1 user thanked author for this post.
11/01/2025 at 12:30 PM #253178Hi,
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…
2 users thanked author for this post.
11/03/2025 at 8:20 AM #253207Hi. Here you have an example of percentile calculation:
1234567891011121314151617181920212223//Percentilep=252rnkCount = 0count = 0FOR i = 1 to p-1count = count + 1IF close[i] < close THENrnkCount = rnkCount + 1endifNEXTPercentileRank = (rnkCount/count)*100drawhline(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 PercentileRank1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on 