The system is very simple. The following assumes that "near" is within 1% of the Bollinger Bands but you can adjust this value as you see fit. Note that the requirement of an inside day significanly reduces the number of signals which may or may not be good. You can experiment with and without Inside(). Here is the system description and code (watch word wrap):
/*
For longs:
1. Look for the currency pair to hit or come very close to hitting the lower Bollinger.
2. Wait for next candle and make sure that the next candle's low is greater than or equal to the previous candle's low and that the high is also less than or equal to the previous period's high.
If so, go long at the open of the third candle.
3. The initial stop is placed a few pips below the previous candle's low.
4. Trail stop on a closing basis with the 20-period SMA.
For shorts:
1. Look for the currency pair to hit or come very close to hitting the upper Bollinger.
2. Wait for next candle and make sure that the next candle's high is less than or equal to the previous candle's high and that the low is also greater than or equal to the previous period's low.
If so, go short at the open of the third candle.
3. The initial stop is placed a few pips above the previous candle's high.
4. Trail stop on a closing basis with the 20-period SMA.
*/
sigma = Param( "Sigma", 2, 1, 3, .1 ); //adjustable
bbPeriod = Param( "BB Period", 20, 5, 50, 1 ); //adjustable
bbt = BBandTop( C, bbPeriod, sigma );
bbb = BBandBot( C, bbPeriod, sigma );
nearBBT = .99 * bbt; //1% = "near"
nearBBB = 1.01 * bbb; //1% = "near"
Buy = IIf( Ref( L, -1 ) >= bbb AND Ref( L, -1 ) <= nearBBB AND Inside(), 1, Null ); //Inside() reduces number of signals
Short = IIf( Ref( H, -1 ) <= bbt AND Ref( H, -1 ) >= nearBBT AND Inside(), 1, Null ); //Inside() reducess number of signals
Buy = ExRem( Buy, Short );
Short = ExRem( Short, Buy );
Plot( C, "", IIf( L >= bbb AND L <= nearbbb, colorYellow, IIf( H <= bbt AND H >= nearbbt, colorRed, colorPaleGreen ) ), styleBar );
Plot( bbb, "", colorWhite, styleThick );
Plot( bbt, "", colorWhite, styleThick );
PlotShapes( ( Buy * shapeUpArrow ) + ( Short * shapeDownArrow ), IIf( Buy, colorYellow, colorRed ), 0, IIf( Buy, L, H ), IIf( Buy, -20, -20 ) );
Plot( nearbbt, "nearBBT", colorRed, styleThick ); //near boundary
Plot( nearbbb, "nearBBB", colorRed, styleThick ); //near boundary
Plot( MA( C, 20 ), "Stop", colorBrightGreen, styleThick ); //Trailing stop