// Downloaded From https://www.WiseStockTrader.com
///Mjoger Bollinger System 1.1
//best results for 5 - and 1 - minutes periods

Stop_Profit = Optimize( "profit point", 0, 0, 40, 1 );   

BollingerPeriods = Optimize( "period bollinger", 16, 3, 25, 1 );   

BollingerWidth = Optimize( "width bollinger", 3, 1, 4, 1 );   

LevelAboveBandTop = Optimize( "above band", 50, 0, 100, 25 );   

RSISIGNAL = Optimize( "rsi signal", 7, 2, 20, 1 );   
   
ApplyStop(stopTypeTrailing, stopModePoint, Stop_Profit, 0, False, 0);   

 
BuyShortPosition = Close>BBandTop(Close, BollingerPeriods,BollingerWidth ) || Open>BBandTop(Close, BollingerPeriods,BollingerWidth )
							 || High>BBandTop(Close, BollingerPeriods,BollingerWidth );

//for backtesting = buy only one contract/share

PositionSize = MarginDeposit = 1;


BuyShortPositionPriceSignalPercent = 0;

diffCloseOpen = abs(Close-Open);
diffCloseBollingerTop = abs(Close-BBandTop(Close, BollingerPeriods,BollingerWidth ));

BuyShortPositionPriceSignalPercent = IIf( Close<BBandTop(Close, BollingerPeriods,BollingerWidth ) &&  Open<BBandTop(Close, BollingerPeriods,BollingerWidth ), 100,


(diffCloseBollingerTop /diffCloseOpen)*100

);


BuyLongPosition = Close<BBandBot(Close, BollingerPeriods,BollingerWidth ) || Open<BBandBot(Close, BollingerPeriods,BollingerWidth )
							 || High<BBandBot(Close, BollingerPeriods,BollingerWidth );


BuyLongPositionPriceSignalPercent = 0;

diffCloseOpen = abs(Close-Open);
diffCloseBollingerBottom = abs(Close-BBandBot(Close, BollingerPeriods,BollingerWidth ));

BuyLongPositionPriceSignalPercent  = IIf( Close<BBandBot(Close, BollingerPeriods,BollingerWidth ) &&  Open<BBandBot(Close, BollingerPeriods,BollingerWidth ), 100,
//else

(diffCloseBollingerBottom /diffCloseOpen)*100

);

BelowBollingerBand = BuyLongPositionPriceSignalPercent  >= LevelAboveBandTop ;


AboveBollingerBand  = BuyShortPositionPriceSignalPercent >= LevelAboveBandTop ;


Buy=BuyLongPosition && BelowBollingerBand && RSI(RSISIGNAL ) <40 ;

Sell=0;//RSI(RSISIGNAL ) > 90;
 
Short=BuyShortPosition && AboveBollingerBand && RSI(RSISIGNAL ) >80  ; 
 
Cover=0;//RSI(RSISIGNAL ) < 10 ; 


Plot( BBandTop(Close, BollingerPeriods,BollingerWidth ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style")  );
Plot( BBandBot(Close, BollingerPeriods,BollingerWidth ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style")  );

Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorGreen, 0, Close, 0);
PlotShapes(IIf(Sell , shapeDownArrow, shapeNone),colorRed, 0, Close, 0);

PlotShapes(IIf(Short , shapeDownTriangle, shapeNone),colorBrightGreen, 0, Close, -5);
PlotShapes(IIf(Cover , shapeUpTriangle, shapeNone),colorBlue, 0, Close, -5);