This strategy was called AdvancedCTLrev1 strategy. In the code below are the piercing and dark cloud cover removed. Detection of others patterns is improved. Plus a lot of other errors corrected.
First the code:
************************************************************************
strategy candle_pattern_strategy;
/* written by ctlprogrammer for EUR/USD */
/*Warning for demonstration purpose only, no live trading please*/
/*you can freely copy the code but plz leave this header*/
/* www.ctltrading.blogspot.com*/
input lots = 1,tradingallowed = false,Max_allowed_loss=-100,profit_taking_level=100;
vars currentbar(number), maint(series),maout(series),periodATR=14,possible_sell(bool),possible_buy(bool);
begin
/*every candle tells his story*/
currentbar := back(close);
if currentbar < 200 then return;
bollinger_bands();
Average_True_Range();
Fast_Stochastics();
Relative_Strength();
Mov_Avg_Exponential(close,200);
possible_buy:=false;
possible_sell:=false;
strategy candle_pattern_strategy;
/* written by ctlprogrammer for EUR/USD */
/*Warning for demonstration purpose only, no live trading please*/
/*you can freely copy the code but plz leave this header*/
/* www.ctltrading.blogspot.com*/
input lots = 1,tradingallowed = false,Max_allowed_loss=-100,profit_taking_level=100;
vars currentbar(number), maint(series),maout(series),periodATR=14,possible_sell(bool),possible_buy(bool);
begin
/*every candle tells his story*/
currentbar := back(close);
if currentbar < 200 then return;
bollinger_bands();
Average_True_Range();
Fast_Stochastics();
Relative_Strength();
Mov_Avg_Exponential(close,200);
possible_buy:=false;
possible_sell:=false;
/*BULLISH red hammer in downtrend*/
if close[currentbar]<open[currentbar] and
(high[currentbar]-open[currentbar])<0.00002 and
(open[currentbar]-close[currentbar])*2 < (close[currentbar]-low[currentbar]) and
close[currentbar-1]<open[currentbar-1] and
(high[currentbar]-low[currentbar]) > Average_True_Range.line[currentbar]*0.75
then
begin
alert("text","bullish red hammer in a downtrend");
possible_buy:=true;
end;
/*BULLISH green hammer in downtrend*/
if close[currentbar]>open[currentbar] and
(high[currentbar]-close[currentbar])<0.00002 and
(close[currentbar]-open[currentbar])*2 < (open[currentbar]-low[currentbar]) and
close[currentbar-1]<open[currentbar-1] and
(high[currentbar]-low[currentbar]) > Average_True_Range.line[currentbar]*0.75
then
begin
alert("text","bullish green hammer in a downtrend");
possible_buy:=true;
end;
if close[currentbar]<open[currentbar] and
(high[currentbar]-open[currentbar])<0.00002 and
(open[currentbar]-close[currentbar])*2 < (close[currentbar]-low[currentbar]) and
close[currentbar-1]<open[currentbar-1] and
(high[currentbar]-low[currentbar]) > Average_True_Range.line[currentbar]*0.75
then
begin
alert("text","bullish red hammer in a downtrend");
possible_buy:=true;
end;
/*BULLISH green hammer in downtrend*/
if close[currentbar]>open[currentbar] and
(high[currentbar]-close[currentbar])<0.00002 and
(close[currentbar]-open[currentbar])*2 < (open[currentbar]-low[currentbar]) and
close[currentbar-1]<open[currentbar-1] and
(high[currentbar]-low[currentbar]) > Average_True_Range.line[currentbar]*0.75
then
begin
alert("text","bullish green hammer in a downtrend");
possible_buy:=true;
end;
/*BEARISH green hanging man in uptrend*/
if close[currentbar]>open[currentbar] and
(high[currentbar]-close[currentbar])<0.00002 and
(close[currentbar]-open[currentbar])*2 < (open[currentbar]-low[currentbar]) and
close[currentbar-1]>open[currentbar-1] and
(high[currentbar]-low[currentbar]) > Average_True_Range.line[currentbar]*0.75
then
begin
alert("text","bearish green hanging man in uptrend");
possible_sell:=true;
end;
if close[currentbar]>open[currentbar] and
(high[currentbar]-close[currentbar])<0.00002 and
(close[currentbar]-open[currentbar])*2 < (open[currentbar]-low[currentbar]) and
close[currentbar-1]>open[currentbar-1] and
(high[currentbar]-low[currentbar]) > Average_True_Range.line[currentbar]*0.75
then
begin
alert("text","bearish green hanging man in uptrend");
possible_sell:=true;
end;
/*BEARISH red hanging man in uptrend*/
if close[currentbar]<open[currentbar] and
(high[currentbar]-open[currentbar])<0.00002 and
(open[currentbar]-close[currentbar])*2 < (close[currentbar]-low[currentbar]) and
close[currentbar-1]>open[currentbar-1] and
(high[currentbar]-low[currentbar]) > Average_True_Range.line[currentbar]*0.75
then
begin
alert("text","bearish red hanging man in uptrend");
possible_sell:=true;
end;
/*BULLISH engulfing matching low*/
if close[currentbar]>open[currentbar] and
close[currentbar-1]<open[currentbar-1] and
close[currentbar-2]<open[currentbar-2] and
close[currentbar]>high[currentbar-1] and
low[currentbar-1]-0.0001 <low[currentbar]and low[currentbar]<low[currentbar-1]+0.0001 and
close[currentbar-1] -0.0001<open[currentbar]and open[currentbar]<close[currentbar-1]+0.0001 and
close[currentbar]>open[currentbar-1] and
(high[currentbar]-low[currentbar]) > Average_True_Range.line[currentbar]*0.75 and
(high[currentbar-1]-low[currentbar-1]) > Average_True_Range.line[currentbar]*0.75
then
begin
alert("text","bullish engulfing matching low");
possible_buy:=true;
end;
/*BEARISH engulfing matching high*/
if close[currentbar]<open[currentbar] and
close[currentbar-1]>open[currentbar-1] and
close[currentbar-2]>open[currentbar-2] and
close[currentbar]<low[currentbar-1] and
high[currentbar-1]-0.0001 <high[currentbar]and high[currentbar]<high[currentbar-1]+0.0001 and
close[currentbar-1] -0.0001<open[currentbar]and open[currentbar]<close[currentbar-1]+0.0001 and
close[currentbar]<open[currentbar-1] and
(high[currentbar]-low[currentbar]) > Average_True_Range.line[currentbar]*0.75 and
(high[currentbar-1]-low[currentbar-1]) > Average_True_Range.line[currentbar]*0.75
then
begin
alert("text","bearish engulfing matching high");
possible_sell:=true;
end;
if close[currentbar]<open[currentbar] and
(high[currentbar]-open[currentbar])<0.00002 and
(open[currentbar]-close[currentbar])*2 < (close[currentbar]-low[currentbar]) and
close[currentbar-1]>open[currentbar-1] and
(high[currentbar]-low[currentbar]) > Average_True_Range.line[currentbar]*0.75
then
begin
alert("text","bearish red hanging man in uptrend");
possible_sell:=true;
end;
/*BULLISH engulfing matching low*/
if close[currentbar]>open[currentbar] and
close[currentbar-1]<open[currentbar-1] and
close[currentbar-2]<open[currentbar-2] and
close[currentbar]>high[currentbar-1] and
low[currentbar-1]-0.0001 <low[currentbar]and low[currentbar]<low[currentbar-1]+0.0001 and
close[currentbar-1] -0.0001<open[currentbar]and open[currentbar]<close[currentbar-1]+0.0001 and
close[currentbar]>open[currentbar-1] and
(high[currentbar]-low[currentbar]) > Average_True_Range.line[currentbar]*0.75 and
(high[currentbar-1]-low[currentbar-1]) > Average_True_Range.line[currentbar]*0.75
then
begin
alert("text","bullish engulfing matching low");
possible_buy:=true;
end;
/*BEARISH engulfing matching high*/
if close[currentbar]<open[currentbar] and
close[currentbar-1]>open[currentbar-1] and
close[currentbar-2]>open[currentbar-2] and
close[currentbar]<low[currentbar-1] and
high[currentbar-1]-0.0001 <high[currentbar]and high[currentbar]<high[currentbar-1]+0.0001 and
close[currentbar-1] -0.0001<open[currentbar]and open[currentbar]<close[currentbar-1]+0.0001 and
close[currentbar]<open[currentbar-1] and
(high[currentbar]-low[currentbar]) > Average_True_Range.line[currentbar]*0.75 and
(high[currentbar-1]-low[currentbar-1]) > Average_True_Range.line[currentbar]*0.75
then
begin
alert("text","bearish engulfing matching high");
possible_sell:=true;
end;
if tradingallowed=true then
begin
/* this part defines the entries */
if possible_sell=true and Mov_Avg_Exponential.line[currentbar-1]>Mov_Avg_Exponential.line[currentbar] and
(Relative_Strength.line[currentbar]>50 or high[currentbar]>Bollinger_Bands.line_upper[currentbar] or Fast_Stochastics.line_k[currentbar]>80) then sell(lots);
if possible_buy=true and
(Relative_Strength.line[currentbar]<50 or low[currentbar]<Bollinger_Bands.line_lower[currentbar] or Fast_Stochastics.line_k[currentbar]<20) then buy(lots);
/*this part defines the exits */
if long() and Mov_Avg_Exponential.line[currentbar-1]<Mov_Avg_Exponential.line[currentbar] and
(Relative_Strength.line[currentbar]>70 or high[currentbar]>Bollinger_Bands.line_upper[currentbar] or Fast_Stochastics.line_k[currentbar]>80) then exitlong();
if short() and
(Relative_Strength.line[currentbar]<30 or low[currentbar]<Bollinger_Bands.line_lower[currentbar] or Fast_Stochastics.line_k[currentbar]<20) then exitlong();
/*this part defines a basic money mangagment*/
if fpl()<Max_allowed_loss then
begin
if long() then exitlong();
if short() then exitshort();
end;
if fpl()>profit_taking_level then
begin
if long() then exitlong();
if short() then exitshort();
end;
begin
/* this part defines the entries */
if possible_sell=true and Mov_Avg_Exponential.line[currentbar-1]>Mov_Avg_Exponential.line[currentbar] and
(Relative_Strength.line[currentbar]>50 or high[currentbar]>Bollinger_Bands.line_upper[currentbar] or Fast_Stochastics.line_k[currentbar]>80) then sell(lots);
if possible_buy=true and
(Relative_Strength.line[currentbar]<50 or low[currentbar]<Bollinger_Bands.line_lower[currentbar] or Fast_Stochastics.line_k[currentbar]<20) then buy(lots);
/*this part defines the exits */
if long() and Mov_Avg_Exponential.line[currentbar-1]<Mov_Avg_Exponential.line[currentbar] and
(Relative_Strength.line[currentbar]>70 or high[currentbar]>Bollinger_Bands.line_upper[currentbar] or Fast_Stochastics.line_k[currentbar]>80) then exitlong();
if short() and
(Relative_Strength.line[currentbar]<30 or low[currentbar]<Bollinger_Bands.line_lower[currentbar] or Fast_Stochastics.line_k[currentbar]<20) then exitlong();
/*this part defines a basic money mangagment*/
if fpl()<Max_allowed_loss then
begin
if long() then exitlong();
if short() then exitshort();
end;
if fpl()>profit_taking_level then
begin
if long() then exitlong();
if short() then exitshort();
end;
end;
end.
end.
No comments:
Post a Comment