//-----------------------------------------------
//PRC_Gold Strategy
//version = 0
//15.09.2025
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//-----------------------------------------------
// --- STRATEGY SETTINGS & PARAMETERS ---
DEFPARAM CumulateOrders = false
longlenght = 58
maxProfit = 4250
stopLossValue = maxProfit * 0.3
//-----------------------------------------------
// --- LONG ENTRY LOGIC ---
//-----------------------------------------------
// Indicator definitions for the long entry condition.
myADX14 = ADX[14]
myRSI14 = RSI[14](close)
myStdDev20 = STD[20](close)
myADX5 = ADX[5]
// This filter group must be FALSE for a long entry to be considered.
longFilter = (myADX14 > 60 AND myRSI14 > 60 AND myStdDev20 > myStdDev20[1])
// Main long entry condition:
IF NOT LongOnMarket AND NOT longFilter AND myADX5 < 50 THEN
entryPrice = HIGHEST[longlenght](high)
BUY 1 CONTRACT AT entryPrice STOP
ENDIF
//-----------------------------------------------
// --- SHORT ENTRY LOGIC ---
//-----------------------------------------------
// Indicator definitions for the short entry condition.
myStdDev10 = STD[10](close)
myCCI14 = CCI[14]
// Filter conditions that must be FALSE for a short entry.
shortFilter1 = (close < LOWEST[21](low)[1])
shortFilter2 = (myStdDev10 > myStdDev20 AND myRSI14 < 40 AND myCCI14 < -100)
// Simplified Pivot Point Logic
ONCE prd = 2 // Period to define the pivot
ONCE pivotH = 0
ONCE pivotL = 0
// Pivot High Detection
ph1 = high < high[prd]
ph2 = HIGHEST[prd](high) < high[prd]
ph3 = high[prd] > HIGHEST[prd](high)[prd+1]
IF ph1 AND ph2 AND ph3 THEN
pivotH = high[prd]
ENDIF
// Pivot Low Detection
pl1 = low > low[prd]
pl2 = LOWEST[prd](low) > low[prd]
pl3 = low[prd] < LOWEST[prd](low)[prd+1]
IF pl1 AND pl2 AND pl3 THEN
pivotL = low[prd]
ENDIF
pivotCondition = (pivotH > 0) AND (pivotL > 0) AND (pivotH < pivotL)
// Main short entry condition:
IF NOT ShortOnMarket AND NOT shortFilter1 AND NOT shortFilter2 AND pivotCondition THEN
entryPrice = LOWEST[longlenght](low)
SELLSHORT 1 CONTRACT AT entryPrice STOP
ENDIF
//-----------------------------------------------
// --- EXIT MANAGEMENT ---
//-----------------------------------------------
// Fixed stop loss and profit target.
SET STOP $LOSS stopLossValue
SET TARGET $PROFIT maxProfit
// Dynamic Trailing Stop based on a 10-period high/low.
IF LongOnMarket THEN
exitLevel = LOWEST[10](low)
SELL AT exitLevel STOP
ENDIF
IF ShortOnMarket THEN
exitLevel = HIGHEST[10](high)
EXITSHORT AT exitLevel STOP
ENDIF