(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
5 Comments

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: 41
Download
Filename: TEST-STRAT-INDIC.itf
Downloads: 51
WE ARE SOCIETY Senior
I usually let my code do the talking, which explains why my bio is as empty as a newly created file. Bio to be initialized...
Author’s Profile

Comments

Logo Logo
Loading...