top of page

DAX AI BOT

Code below. Runs on DAX40 on 3 minute timeframe:


//DAX M3


// Unified ProRealAlgos - Adaptive regime algo (ProRealTime v11)

// Combines trend following, mean reversion and breakout logic

// Focus: signal generation. Single clean risk block. No license checks.

// Variable naming rules respected: no underscores, no indicator names in variable names.


// ----------------- BASIC SETTINGS -----------------

DEFPARAM cumulateorders = false

DEFPARAM preloadbars = 10000


// Enable directions


longEnabled = 1 // 1 = allow longs, 0 = block

shortEnabled = 1 // 1 = allow shorts, 0 = block



// Position sizing (simple fixed by default; you may replace with your own MM)

posSizeLong = 25

posSizeShort = 25


// Risk settings (single clean block)

stopLossPct = 4.1 // default stop loss percent (5%)

takeProfitPct = 0 // 0 = disabled. Set e.g. 10 for 10% TP

useTrailing = 1 // 1 = enable simple trailing once in profit, 0 = no trailing

trailingStartPct = 1 // start trailing after N% profit

trailingPctKeep = 1 // keep this percent of the max profit as trailing stop


// Regime parameters (tuneable)

longTermFastLen = 13

longTermSlowLen = 26

trendSmoothLen =51


if date < 20251021 then


breakoutRange = 20 // bars to compute recent high/low for breakout

breakoutVolLen = 20 // volatility length for bandwidth

meanRevOscLen = 14 // oscillator length for mean reversion

meanRevThresholdHigh = 70

meanRevThresholdLow = 30

meanRevAtrMult = 1.5// entry if price deviates by ATR*mult


// Minimal time filter example (from originals). Set to 0 to disable.

timeFilterActive = 0

timeStart = 10000 // example HHMMSS window start

timeEnd = 10000 // example HHMMSS window end



// ----------------- HELPER CALCS -----------------

// Long term moving lines (no indicator names in variable names)

fastLine = Average[longTermFastLen](close)

slowLine = Average[longTermSlowLen](close)

trendLine = Average[trendSmoothLen](close)


// MACD style momentum using builtins (we will only use sign and slope)

macdLine23 = MACDline[12,26,9](close)

macdSignal23 = MACD[12,26,9](close)


// Volatility and bandwidth

trueRange = AverageTrueRange[26](close)

bandWidth = (BollingerUp[16] - BollingerDown[16]) / Average[16](close)


// Oscillator used for mean reversion (we will call the function but avoid naming variable 'rsi')

oscillatorValue = RSI[meanRevOscLen](close)


// Recent high/low for breakout

recentHigh = Highest[breakoutRange](high)

recentLow = Lowest[breakoutRange](low)


// Trend definitions

isStrongUp = (fastLine > slowLine) AND (slowLine > trendLine) AND (macdLine > macdSignal)

isStrongDown = (fastLine < slowLine) AND (slowLine < trendLine) AND (macdLine < macdSignal)


// Volatility regime: lowVol indicates we might favor mean reversion

lowVol = bandWidth < 0.01 OR trueRange < AverageTrueRange[breakoutVolLen](close) // tuneable


// Decide market regime numeric: 1 = trend, 2 = meanrev, 3 = breakout

regime = 3

IF isStrongUp OR isStrongDown THEN

regime = 1

ELSIF lowVol THEN

regime = 2

ELSE

regime = 3

ENDIF


// Optional time filter applied to entries

timeOk = 1

IF timeFilterActive = 1 THEN

timeOk = (time >= timeStart AND time <= timeEnd)

ENDIF


// ----------------- ENTRY LOGIC -----------------

// We will generate a long signal variable and a short signal variable

longSignal = 0

shortSignal = 0


// ----- Trend following regime (pullback + momentum) -----

// Idea: when long term trend is up, buy pullbacks that show short term strength

IF regime = 1 AND timeOk THEN

// Long trend

IF isStrongUp AND longEnabled THEN

// Pullback condition: price below fastLine but above slowLine and oscillator not extreme low

condPullbackLong = close < fastLine AND close > slowLine AND oscillatorValue > meanRevThresholdLow

// Momentum confirmation: last bar close higher than previous

condMomentumLong = close > close[1]

IF condPullbackLong AND condMomentumLong THEN

longSignal = 1

ENDIF

ENDIF


// Short trend

IF isStrongDown AND shortEnabled THEN

condPullbackShort = close > fastLine AND close < slowLine AND oscillatorValue < meanRevThresholdHigh

condMomentumShort = close < close[1]

IF condPullbackShort AND condMomentumShort THEN

shortSignal = 1

ENDIF

ENDIF

ENDIF


// ----- Mean reversion regime (range) -----

// Idea: when volatility low and oscillator extreme, fade the extreme

IF regime = 2 AND timeOk THEN

// Long mean reversion: oscillator extreme low AND price below moving center by ATR*mult

centerLine = Average[80](close) // center to revert toward

IF longEnabled THEN

condOscLow = oscillatorValue < meanRevThresholdLow

condPriceLow = close < centerLine - (trueRange * meanRevAtrMult)

IF condOscLow AND condPriceLow THEN

longSignal = 1

ENDIF

ENDIF

// Short mean reversion

IF shortEnabled THEN

condOscHigh = oscillatorValue > meanRevThresholdHigh

condPriceHigh = close > centerLine + (trueRange * meanRevAtrMult)

IF condOscHigh AND condPriceHigh THEN

shortSignal = 1

ENDIF

ENDIF

ENDIF


// ----- Breakout regime -----

// Idea: if not trending and volatility moderate/high, break recent range

IF regime = 3 AND timeOk THEN

breakoutBuffer = trueRange * 0

// Long breakout

IF longEnabled THEN

condBreakLong = close > recentHigh AND close > fastLine

IF condBreakLong THEN

longSignal = 1

ENDIF

ENDIF

// Short breakout

IF shortEnabled THEN

condBreakShort = close < recentLow AND close < fastLine

IF condBreakShort THEN

shortSignal = 1

ENDIF

ENDIF

ENDIF


// ----------------- EXECUTION & RISK -----------------

// Only one entry direction per bar, prioritize trend then breakout then meanrev

// (this reduces conflicting signals)

entryLongNow = 0

entryShortNow = 0


IF longSignal AND NOT shortSignal THEN

entryLongNow = 1

ELSIF shortSignal AND NOT longSignal THEN

entryShortNow = 1

ELSIF longSignal AND shortSignal THEN

// Conflict resolution: prefer trend regime if present, else prefer breakout

IF regime = 1 AND isStrongUp THEN

entryLongNow = 1

ELSIF regime = 3 THEN

// choose signal based on distance from center

entryDir = (abs(close - recentHigh) < abs(close - recentLow))

IF entryDir = 1 THEN

entryLongNow = 1

ELSE

entryShortNow = 1

ENDIF

ELSE

// fallback long

entryLongNow = 1

ENDIF

ENDIF


// Place orders and apply the unique risk block

IF entryLongNow = 1 THEN

BUY posSizeLong CONTRACT AT MARKET

// Set percent stoploss (single clean implementation)

SET STOP %LOSS stopLossPct

IF takeProfitPct > 0 THEN

SET TARGET %PROFIT takeProfitPct

ENDIF

ENDIF


IF entryShortNow = 1 THEN

SELLSHORT posSizeShort CONTRACT AT MARKET

SET STOP %LOSS stopLossPct

IF takeProfitPct > 0 THEN

SET TARGET %PROFIT takeProfitPct

ENDIF

ENDIF



// Safety: end of day flatten (example from originals)

IF dayofweek = 5 AND time >= 214500 THEN

IF LongOnMarket THEN

SELL AT MARKET

ENDIF

IF ShortOnMarket THEN

EXITSHORT AT MARKET

ENDIF

ENDIF


// End of algo


else


if rsi[14]<95 then

BUY 25 CONTRACT AT MARKET

// Set percent stoploss (single clean implementation)

SET STOP %LOSS 3


endif


endif


if date = 20251031 and time >= 100000 then

exitshort at market

SELL AT MARKET

endif




 
 
 

Recent Posts

See All

Don't trade for 8 hours straight

seats available - 9 persons in waitlist

ProRealTime made easy

CFDs are complex instruments and come with a high risk of losing money rapidly due to leverage. On average 71% of retail investor accounts lose money when trading CFDs. Past performance is no guarantee of future results. You should consider whether you understand how CFDs work before starting.

Read full terms and conditions

ProRealTime™ is a trademark registered by the third-party entity ProRealTime SAS

We have no link with the ProRealTime™ entity that offers the ProRealTime™ trading software

Copyright ProRealAlgos 580648-4231
Harju maakond, Tallinn, Kesklinna linnaosa, Pille 13, 10173

bottom of page