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