// === PARAMETERS ===
supportLookback = 50
resistanceLookback = 50
testTolerance = 2.0 // Looser tolerance for matching levels
minTests = 1 // Allow support/resistance with only 1 test
atrPeriod = 14
minATRMultiplier = 1.0 // Less strict ATR confirmation
// === VARIABLES ===
strongSupport = 0
strongResistance = 0
supportTests = 0
resistanceTests = 0
// === ATR Calculation ===
atr = AverageTrueRange[atrPeriod]
avgATR = Average[atrPeriod](atr)
atrConfirmed = atr >= minATRMultiplier * avgATR
// === DETECT STRONG SUPPORT ===
for i = 1 to supportLookback do
if close[i] < close[i+1] and close[i] < close[i-1] then
level = close[i]
tests = 0
for j = 1 to supportLookback do
if abs(close[j] - level) <= testTolerance then
tests = tests + 1
endif
next
if tests >= minTests then
strongSupport = level
supportTests = tests
break
endif
endif
next
// === DETECT STRONG RESISTANCE ===
for i = 1 to resistanceLookback do
if close[i] > close[i+1] and close[i] > close[i-1] then
level = close[i]
tests = 0
for j = 1 to resistanceLookback do
if abs(close[j] - level) <= testTolerance then
tests = tests + 1
endif
next
if tests >= minTests then
strongResistance = level
resistanceTests = tests
break
endif
endif
next
// === DEBUG VISUALIZATION ===
if strongSupport > 0 then
DRAWSEGMENT(barindex - 10, strongSupport, barindex, strongSupport) COLOURED(0,255,0)
endif
if strongResistance > 0 then
DRAWSEGMENT(barindex - 10, strongResistance, barindex, strongResistance) COLOURED(255,0,0)
endif
// === ENTRY CONDITIONS ===
buySignal = close <= strongSupport and atrConfirmed
sellSignal = close >= strongResistance and atrConfirmed
// === EXECUTE TRADES ===
IF buySignal THEN
BUY 1 CONTRACT AT MARKET
ENDIF
IF sellSignal THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// === OPTIONAL: EXIT LOGIC ===
// SET STOP pLOSS 5
// SET TARGET pPROFIT 10
Could anyone help in checking this code and fix any error
If you comment out the Drawing instructions (as below) then it works fine.
Drawing instructions dont work in Auto-Trading.
Drawing instructions only work on Indicators.
if strongSupport > 0 then
//DRAWSEGMENT(barindex – 10, strongSupport, barindex, strongSupport) COLOURED(0,255,0)
endif