WE ARE SOCIETY

(Bollinger Trailing Stop) – CAC 40 Spread Strategy 3 min

Category: Strategies By: WE ARE SOCIETY Created: February 2, 2026, 2:10 PM
February 2, 2026, 2:10 PM
Strategies
8 Comments
(Bollinger Trailing Stop) – CAC 40 Spread Strategy 3 min

This ProOrder code (strategy) implements a trend tracking system based on a crossing of the price with Bollinger-type bands and a dynamic trailing stop. It is designed to work on the CAC 40 (Spread) in a 3-minute timeframe, with hourly/daily filtering rules and risk management via stop loss and target.


Description

The logic calculates an envelope around the average (implicit simple moving average via average) using the standard deviation (std):

  • Upper band (bbup) = average(SignalPeriod) + standard deviation(SignalPeriod) × ArrowPeriod
  • Lower band (bbdn) = average(SignalPeriod) − standard deviation(SignalPeriod) × ArrowPeriod

A trend state (trend) and a trailing stop level (ts) are initialized on the first signal:

  • If the price crosses above the upper band, the trend changes to bullish and the trailing stop is placed on the lower band.
  • If the price crosses below the lower band, the trend changes to bearish and the trailing stop is placed on the upper band.

The trailing stop is then updated to follow the trend (max in uptrend, min in downtrend). A reversal is detected when the price crosses the trailing stop. The code also contains a time filter (stopv) to avoid certain time slots/days.

Important: in the extract provided, the variable sale is initialized to 0 and is never set to 1, while only purchase is set to 1 during a reversal (trend=1 then crossing below ts). In addition, the order executed is a SELLSHORT conditioned by sale=1. As it stands, the strategy may therefore not trigger any trades. This documentation describes the calculation as written, but it is advisable to check/complete the entry conditions.

Configuration

  • DEFPARAM cumulateOrders = FALSE: prevents the accumulation of positions (only one position at a time).
  • defparam preloadbars = 10000: number of bars preloaded to stabilize calculations (mean/standard deviation).
  • timeframe (3 MINUTE): time unit used by the strategy.
  • SignalPeriod = 28: calculation period for the mean and standard deviation (basis for the bands).
  • ArrowPeriod = 2: multiplier applied to the standard deviation (width of the bands).
  • Day filter (journee): based on time173000 (after 5:30 p.m., journee=0 otherwise 1).
  • Hourly filter stopv: enables/disables the possibility of executing the order according to the day of the week and hourly conditions (see code).
  • set target profit 9: profit target (in points/units depending on the instrument and broker).
  • set stop loss 70: stop loss (in points/units depending on the instrument and broker).
REM CAC 40 SPREAD 1
DEFPARAM cumulateOrders = FALSE
defparam preloadbars= 10000
timeframe (3 MINUTE)
if time<090000 or time>173000 then
journee=0
else
journee=1
endif
SignalPeriod = 28
ArrowPeriod = 2
achat=0
vente=0
bbup = average[signalperiod]+std[signalperiod]*arrowperiod
bbdn = average[signalperiod]-std[signalperiod]*arrowperiod
if ts=0 then
if close crosses over bbup then
ts=bbdn
trend=1
elsif close crosses under bbdn then
ts=bbup
trend=-1
endif
endif
if trend=1 then
ts=max(ts,bbdn)
elsif trend=-1 then
ts=min(ts,bbup)
endif
if trend=1 and close crosses under ts then
trend=-1
ts=bbup
r=255
g=0
achat=1
endif
if ((dayofweek=3 or dayofweek=5) and time<093500) or (dayofweek=5 and time>105000 and time<120000)or (dayofweek=1 and time>150000 and time<153000) then
stopa=0
else
stopa=1
endif
if journee=1 and achat=1 and stopa=1 then
buy 1 contract at market
endif
if trend=-1 and close crosses over ts then
trend=1
ts=bbdn
r=0
g=255
vente=1
endif
if (time>130100 and time<143000) or (time>105500 and time<120000) or (time>145500 and time<151500) or (dayofweek=5 and time<090500) then
stopv=0
else
stopv=1
endif
if journee=1 and vente=1 and stopv=1 then
sellshort at market
endif
set target profit 9
set stop loss 70

How to use

  1. Open ProRealTime and create a new ProOrder strategy, then paste the code.
  2. Check the time unit: the strategy forces the timeframe (3 MINUTES). Apply it to a chart compatible with your CAC 40 (Spread) feed.
  3. Backtest over a sufficiently long period (preloading is set to 10,000 bars) and check the behavior of the signals.
  4. Check the entry conditions: as it stands, the sellshort order depends on sale=1, whereas sale is never modified. Adjust/complete if the objective is to open positions.
  5. Set the risk: adapt set target profit and set stop loss to the volatility and costs (spread) of the instrument.
  6. Before using in real life, test on a demo account and check the impact of the time filters (stopv) and the journee variable.

Download
Filename: Capture-decran-2026-02-02-105846.jpg
Downloads: 75
Download
Filename: TEST-STRAT-INDIC.itf
Downloads: 112
WE ARE SOCIETY
WE ARE SOCIETY Senior
Operating in the shadows, I hack problems one by one. My bio is currently encrypted by a complex algorithm. Decryption underway...
Author’s Profile

Comments

GraHal
5 months ago
#

Short78

Too bad I can't attach to my comment the screenshots of the result

It's because this Thread is in the Library (you may know this).

You would have to raise a Topic in the Forum for Strategies in order to be able to attach images etc.

Corto78
5 months ago
#

Ok, je reposte car la copie de l'écran n'a pas l'air d'être accepté.

Le résultat était peut-être bon de Aout 2025 à Févr 2026 mais depuis c'est retour à la base départ.

En gros sur la période testée, Résultat = -1529,10€ malgré 77% de trades gagnants. Le problème est que le gain moyen est de 8,58€ pour une perte moyenne de -35,14. Le ratio Gais/Pertes est très bas à 0,84

Dommage que je ne puisse pas joindre à mon commentaire les copies d'écran de résultat

Corto78
5 months ago
#

Bonjour, testé sur 200k unités soit depuis Octobre 2024 jusqu'à ce jour en 3 minutes

 

NASDAQQ
8 months ago
#

excellent

WE ARE SOCIETY
8 months ago
#

REM CAC 40 SPREAD 1 Timeframe prooder 5 secondes

DEFPARAM cumulateOrders = FALSE

defparam preloadbars= 10000

timeframe (3 minute)

if time<090000 or time>173000 then

journee=0

else

journee=1

endif

SignalPeriod = 30

ArrowPeriod = 2

achat=0

vente=0

capital=1000

capital2=capital+STRATEGYPROFIT[0]

taille=(capital2/(close*5.75/100))

n=taille

timeframe (21 minute)

if supertrend[3,10]>close then

trend21m=0

else

trend21m=1

endif

timeframe (3 minute)

bbup = average[signalperiod]+std[signalperiod]*arrowperiod

bbdn = average[signalperiod]-std[signalperiod]*arrowperiod

if ts=0 then

if close crosses over bbup then

ts=bbdn

trend=1

elsif close crosses under bbdn then

ts=bbup

trend=-1

endif

endif

if trend=1 then

ts=max(ts,bbdn)

elsif trend=-1 then

ts=min(ts,bbup)

endif

if trend=1 and close crosses under ts then

trend=-1

ts=bbup

r=255

g=0

achat=1

endif

if ((dayofweek=3 or dayofweek=5) and time<093500) or (dayofweek=5 and time>105000 and time<120000)or (dayofweek=1 and time>150000 and time<153000) or close>highest[100][1]-14 or (dayofweek=4 and trend21m=0 and time>130000 and time<140000) then

stopa=0

else

stopa=1

endif

if journee=1 and achat=1 and stopa=1 then

buy n contract at market

endif

if trend=-1 and close crosses over ts then

trend=1

ts=bbdn

r=0

g=255

vente=1

endif

if (time>130100 and time<143000) or (time>105500 and time<120000) or (time>145500 and time<151500) or (dayofweek=5 and time<090500) or close<lowest[2][1]+3 then

stopv=0

else

stopv=1

endif

if journee=1 and vente=1 and stopv=1 then

sellshort n contract at market

endif

set target profit 9

set stop loss 70

Maik2404
8 months ago
#

Hallo. Ich bekomme immer folgende Fehlermeldung wenn ein Trade gestartet ist. Welche Einstellung muß ich im Code ändern? Frankreich 2€ Zeitrahmen 5 Sekunden.

Maik2404
8 months ago
#

ich kann leider keine Screenshots einfügen

Nicolas
8 months ago
#

Hi, thanks a lot for sharing this strategy. Especially for French CAC40 which isn't as usual as DAX in our codes library! :-D

ProRealCode ProRealCode
Loading...