defparam preLoadBars = 10000
defparam cumulateOrders = false
atrPeriods = 39 // ATR calculation period
// Variables
trueRange = Max(High - Low, Max(Abs(High - Close[1]), Abs(Low - Close[1])))
atr = Average[atrPeriods](trueRange) // ATR based on True Range
// Dynamic Position Sizing
// User Inputs
riskPercent = 1 // Risk percentage for position sizing
portfolioSize = 20000 // Default portfolio size
// ATR calculation period
contractsToTrade = 1 // Number of contracts to trade
// Position Sizing Calculation
positionEquity = Max(PortfolioEquity, portfolioSize) // Use real equity or default portfolio size
contractsToTrade = (riskPercent / 100 * positionEquity) / (atr * PointValue)
// Indicators
bodyRatio = abs(close-open) / (high-low)
// Conditions
cl = summation[3](close-open)=3
cl = cl and highest[3](bodyRatio) >= 0.7
clk = summation[3](close-open)=-3
// Action
if cl then
buy contractsToTrade contract at market
endif
if clk then
sell contractsToTrade contract at market
endif