First the code:
************************************************************************
strategy BBSEMAX2;/* written by ctlprogrammer for EUR/USD timeframe 15min*/
/*Warning for demonstration purpose only, no live trading please*/
/*http://ctltrading.blogspot.com*/
input period = 20,periodF=50,periodS=200, lots = 1;
vars currentbar(number), maS(series), maF(series);
begin
bollinger_bands(close, period, 2);
maS := ema(close,periodS);
maF := ema(close,periodF);
currentbar := back(close);
if currentbar <= max (periodF,periodS) then return;
if crossdown(close, bollinger_bands.line_upper) and (maF[currentbar] < maS[currentbar]) and not short() then
begin
sell(lots*2);
alert("sms","short");
end;
if crossup (close, bollinger_bands.line_lower) and (maF[currentbar] > maS[currentbar]) and not long() then
begin
buy(lots*2);
alert("sms","long");
end;
bollinger_bands(close, period, 1);
if crossup (close, bollinger_bands.line_upper) and long() then sell(lots);
if crossdown(close, bollinger_bands.line_lower) and short() then buy(lots);
if crossdown (close, bollinger_bands.line_mid) and long() then sell(lots);
if crossup(close, bollinger_bands.line_mid) and short() then buy(lots);
/*close positions if major trend change */
if crossup(close,maS) then exitshort();
if crossdown(close,maS) then exitlong();
end.
************************************************************************
This strategy goes long with 2 lots when the following conditions are met:
The Exponential Moving Average (period 50) is above the Exponential Moving Average (period 200) and we have an up crossing of the lower bollingerband (period 20, deviation 2). A SMS alert is given.
This strategy goes short with 2 lots when the following conditions are met:
The Exponential Moving Average (period 50) is below the Exponential Moving Average (period 200) and
we have an down crossing of the upper bollingerband (period 20, deviation 2). A SMS alert is given.
This strategy takes profit on 2 different levels:
In the case a long position was taken
- sells 1 lot when their is a down crossing of the lower bollingerband (period 20, deviation 1)
- sells 1 lot when their is a down crossing of the middle bollingerband (period 20, deviation 1)
- position is protected if the pair close below the Exponential Moving Average (period 200) the long position is closed cause this could indicate a major trend change.
In the case a short position was taken
- buys 1 lot when their is a up crossing of the upper bollingerband (period 20, deviation 1)
- buys 1 lot when their is a up crossing of the middle bollingerband (period 20, deviation 1)
- position is protected if the pair close above the Exponential Moving Average (period 200) the short position is closed cause this could indicate a major trend change.
No comments:
Post a Comment