BOLLINGER BANDS CONTRACTION 5min FOREX

Category: Strategies By: Leo Created: May 17, 2018, 7:09 AM
May 17, 2018, 7:09 AM
Strategies
6 Comments

Hi all,

I wanted to share this simple but effective strategy. It is only for 5 min time frame until multi timeframe is working in the platform, I also tested in different forex markets but not in index nor in commodities. Here is the set up for long position (for short position is the opposite).

  • Price is near and above the SMA200 hourly (i.e SMA 2400 period for 5min timeframe and a bollinger bands for definition of “near” by using the variable BB2400).
  • Contraction of Bollinger Bands of period 200 and SMA200 is upwards, contraction defined by the upper band below a maximum of its value in very short term.
  • Open Stop Order at the near term resistance by using a pseudo Donchian Channel customized by me.
  • Exit at my dynamic SAR (you can check information in a forum of me about this topic) also if close is below support. No profit target.
  • Capital management is deactivated but can be activated in the code if needed.

Have a good trade and just tell us your best setup or if you improve the code.

//BOLLINGER CONTRACTION v1.0


DEFPARAM CumulateOrders = false // Cumulating positions deactivated
DEFPARAM PreLoadBars = 5000 //cargar informacion


//VARIABLES TO BE OPTIMIZED
//P1= 30
//Kperiod=0.3
//BB200=1.4
//BB2400=0.5
Ksar=0.001

once T0=030000
once T1=210000
once MaxRisk0=30

//ROBOT CONFIGURATION
once Ktotalrisk=10   //number of times of maxrirk0 for lossing trade
spread=0.9     //Lowest spread for the market
once n=1             //initial size of contracts

// RISK CONTROL IF THINGS ARE GOING WONDERFULL
//n = 1 + (strategyprofit / (34*pipvalue))
//n=SQRT(n)
//n = round(n * 100)
//n = n / 100
//n = min(max(1,n),20)


//SPREAD APROXIMATION
IF TIME < 063000 THEN //(germany time)
 spread=1.7*spread
ELSIF TIME>210000 THEN //(germany time)
 spread=1.7*spread
ENDIF

//ROBOT WORKING TIME (Germany)
IF TIME>T0 and TIME < T1 THEN
 ontime=1
ELSE
 ontime=0
ENDIF

//RISK CONTROL IF WE NEED TO LEARN OF THIS ROBOT
maxrisk=maxrisk0
totalrisk=Ktotalrisk*maxrisk*PIPVALUE //for stop the robot if things are going bad

//------------------------------------------------
//>>>>>>>>>>  SOPORTES Y RESISTENCIAS <<<<<<<<<<<<
//------------------------------------------------

//SOPORTES  Y RESISTENCIAS

highest1=highest[P1](high)
Px1=round(Kperiod*P1)

IF highest1 = highest1[Px1] then
 R1=highest1
ENDIF

lowest1=lowest[P1](low)
IF lowest1 = lowest1[Px1] then
 S1=lowest1
ENDIF

//------------------------------------------------
//>>>>>>>>>>  BOLLINGER CONTRACTION  <<<<<<<<<<<<
//------------------------------------------------

SMA200=average[200](close)
STD200=STD[200](close)
BBupper200=SMA200+BB200*STD200
BBlower200=SMA200-BB200*STD200

SMA2400=average[2400](close)
STD2400=STD[2400](close)
BBupper2400=SMA2400+BB2400*STD2400
BBlower2400=SMA2400-BB2400*STD2400

Contraction200=0
IF SMA200 > SMA200[1] THEN
 IF BBupper200 < highest[P1](BBupper200) then
  contraction200=1
 ENDIF
ELSE
 IF BBlower200 > lowest[P1](BBlower200) then
  contraction200=-1
 ENDIF
ENDIF

//--------------------------------------------------------
//>>>>>>>>>>>>>>>>>>     TRADING     <<<<<<<<<<<<<<<<<<<<<
//--------------------------------------------------------

a1= contraction200=1
a2= close > SMA2400
a3= close < BBupper2400
IF a1 and a2 and a3 then
 IF NOT LongOnMarket AND ontime=1 and DayOfWeek <= 5 THEN
  entrylong= max(R1,high)+1.5*spread*pipsize
  stoplosslong= (entrylong-lowest1)/pipsize + 3*spread
  stoplosslong= min(stoplosslong,maxrisk)
  BUY n CONTRACTS AT entrylong STOP
  SET STOP pLOSS stoplosslong
 ENDIF
ENDIF

b1= contraction200=-1
b2= close < SMA2400
b3= close > BBlower2400
IF b1 and b2 and b3 then
 IF NOT ShortOnMarket AND ontime=1 and DayOfWeek <= 5 THEN
  entryshort= min(S1,low)- 1.5*spread*pipsize
  stoplossshort= (highest1-entryshort)/pipsize+3*spread
  stoplossshort= min(stoplossshort,maxrisk)
  SELLSHORT n CONTRACTS AT entryshort stop
  SET STOP pLOSS stoplossshort
 ENDIF
ENDIF

//---------------------------------------------------------
//>>>>>>>>>>>>>>>>>>   EXIT POSITIONS    <<<<<<<<<<<<<<<<<<
//---------------------------------------------------------

Kexit=1
IF longonmarket THEN
 Kexit=max(1, ( (close-TRADEPRICE)/pipsize )/(0.5*stoplosslong) )
 Kexit=Kexit*Kexit
 //Kexit= Kexit*SQRT(Kexit)
ENDIF
IF shortonmarket THEN
 Kexit=max(1, ( (TRADEPRICE-close)/pipsize)/ (0.5*StopLossShort) )
 Kexit=Kexit*Kexit
 //Kexit= Kexit*SQRT(Kexit)
ENDIF

mySAR=SAR[Ksar*Kexit,Ksar*Kexit,1]


// ---> exit long
IF longonmarket then
 IF close < S1[1]-spread*pipsize THEN
  SELL AT MARKET
 ENDIF

 IF close crosses under MySAR THEN
  SELL AT MARKET
 ENDIF

 IF (close-TRADEPRICE) > 0.5*stoplosslong*pipsize and MySAR<close THEN
  StopPoints=(TRADEPRICE-mySAR)/pipsize+spread
  StopPoints=round(StopPoints*10)/10
  StopPoints=max(0.5,StopPoints)
  SET STOP pLOSS min(StopPoints,maxrisk)
 ENDIF

 IF TIME > 224500 and DayOfWeek=5 then
  SELL AT MARKET
 ENDIF

ENDIF

// --> extit short
IF shortonmarket THEN

 IF close > R1[1]+spread*pipsize THEN
  EXITSHORT AT MARKET
 ENDIF

 IF close crosses over MySAR THEN
  EXITSHORT AT MARKET
 ENDIF

 IF (TRADEPRICE-close) > 0.5*stoplossshort*pipsize and MySAR>close THEN
  StopPoints=(mySAR-TRADEPRICE)/pipsize+spread
  StopPoints=round(StopPoints*10)/10
  StopPoints=max(0.5,StopPoints)
  SET STOP pLOSS min(StopPoints,maxrisk)
 ENDIF

 IF TIME > 224500 and DayOfWeek=5 then
  EXITSHORT AT MARKET
 ENDIF

ENDIF


//Quit the robot if things are going bad
Q=MAX(Q,((STRATEGYPROFIT/n)/pipvalue))
R=Q-(STRATEGYPROFIT/n)/pipvalue
IF R > totalrisk THEN
 QUIT
ENDIF

IF STRATEGYPROFIT < (-1*totalrisk) THEN
 QUIT
ENDIF

Download
Filename: BOLLINGER-CONTRACTION-FOREX5M.itf
Downloads: 849
Leo Veteran
" IF YOU HAVE WEALTH , IT'S A DUTY TO HELP THOSE WHO DON'T " Manoj Bhargava
Author’s Profile

Comments

Logo Logo
Loading...