I ran this code since 7 Dec 2017 (as a test phase on demo account before going live with it) and so far it has delivered £959. Just over a month.
1 minute time frame with 2 mini contracts.
The main reason I add this is becuse may be someone can some changes or even test it yourself and use it as is.
I have other ones on the same basis where I added TS and MFE (also Sir. Nicolas’s code). These are still in testing phase though.
I have tested with various options/variables on various Indices and forex pairs over months.
Because of the variables this code can apply to any forex or Indice on any timeframe. Anything from 10sec to 4hour. You just have to find your own sweet spot that applies to you.
This code will check for 4 (in this case) consecutive bullish or bearish candlesticks.
After that the variables apply – Inverse trading and Cumulate orders.
In this case it will open position in the same direction as the candles/trend. (InverseTrading = 0) and will cumulate orders (CumulateOrder = 1)
//-------------------------------------------------------------------------
//PRC_TS multiple candlesticks | indicator
//01.03.2017
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
//This is not my code.
//Original code was written and published by Sir.Nicolas
//-------------------------------------------------------------------------
// Prevents the system from creating new orders to enter the market or increase position size before the specified time
noEntryBeforeTime = 070000 //UTC +2
timeEnterBefore = time >= noEntryBeforeTime
// Prevents the system from placing new orders to enter the market or increase position size after the specified time
noEntryAfterTime = 190000 //UTC +2
timeEnterAfter = time < noEntryAfterTime
// --- parameters
Size = 2 //position size
StopLoss = 40 //stoploss in points
TakeProfit = 20 //takeprofit in points
Xcandlesticks = 4 //consecutive bullish or bearish candlesticks to open a new position
InverseTrading = 0 //(0=false ; 1=true) trade in the same direction of the candlesticks pattern or not
CumulateOrder = 1 //(0=false ; 1=true) cumulate or not a new trade if the current candlestick is in the same trend as the pattern
// ------------
//detecting patterns
bearpattern = summation[Xcandlesticks](close<open)=Xcandlesticks
bullishpattern = summation[Xcandlesticks](close>open)=Xcandlesticks
//first order
if not onmarket and timeEnterBefore and timeEnterAfter then
if bearpattern then
if InverseTrading then
BUY Size CONTRACTS AT MARKET
else
SELLSHORT Size CONTRACT AT MARKET
endif
lastbar = barindex
lastpattern = -1
endif
if bullishpattern then
if InverseTrading then
SELLSHORT Size CONTRACT AT MARKET
else
BUY Size CONTRACTS AT MARKET
endif
lastbar = barindex
lastpattern = 1
endif
endif
//cumulate order when a new pattern occurred
if onmarket and timeEnterBefore and timeEnterAfter and not CumulateOrder and barindex-lastbar>=Xcandlesticks then
if bearpattern then
if InverseTrading then
BUY Size CONTRACTS AT MARKET
else
SELLSHORT Size CONTRACT AT MARKET
endif
lastbar = barindex
endif
if bullishpattern then
if InverseTrading then
SELLSHORT Size CONTRACT AT MARKET
else
BUY Size CONTRACTS AT MARKET
endif
lastbar = barindex
endif
endif
//cumulate order when a new consecutive candletick happen right after the pattern occurred
if onmarket and timeEnterBefore and timeEnterAfter and CumulateOrder and barindex-lastbar=1 then
if longonmarket then
if (close>open and lastpattern=1) or (close<open and lastpattern=-1) then
BUY Size CONTRACTS AT MARKET
lastbar = barindex
endif
endif
if shortonmarket then
if (close>open and lastpattern=1) or (close<open and lastpattern=-1) then
SELLSHORT Size CONTRACT AT MARKET
lastbar = barindex
endif
endif
endif
SET STOP PLOSS StopLoss
SET TARGET PPROFIT TakeProfit
//END
May be someone can some changes or even test it yourself and use it as is.
I have tested the various options/variables on various Indices and forex pairs over months.
Because of the variables this code can apply to any forex or Indice on any timeframe. Anything from 10sec to 4hour. You just have to find your own sweet sport that applies to you.
This code will check for 4 (in this case) consecutive bullish or bearish candlesticks.
After that the variables apply – Inverse trading and Cumulate orders.
In this case it will open position in the same direction as the candles/trend. (InverseTrading = 0) and will cumulate orders (CumulateOrder = 1)
Dear Andre
Thanks for sharing your code that could be used on several intruments.
I copy, modified your code to utc+1 time frame.
But I get different results?
Do you have an idea why it is so different?
Regards
Hi Yannick
I got similar to you! I tried it on several instruments and several time frames, gave up in the end … unusual for me as I like a challenge!
Looks like some good code in the Strat, hope somebody gets it going!? 🙁
GraHal
I dont know why you would get different results.
May be leave it at the times I put in UTC+2
The results I posted is the code that ran on demo account and not backtest results.
Hi Andre
Aha … I backtested (not demo trade) so that will be the reason for my difference from your results.
I’m sure Yannick results are backtested also … hence his difference.
Cheers
GraHal
Hi
Thanks @Andre Vorster
Could share the graph or trade opened and strategy performance (evolution of equity versus time)?
Regards
Yannick.
I’m not sure I understand your question correct.
Can you please elbaborate.
Hi Andre
The profit /loss evolution of your real equity using this strategy.
(similar to the backtested one that I linked)
Please accept my apologies Andre for earlier comments.
I backtested your Strat over same period as you ran it in Demo and I got good results … about twice as good as yours! 🙂 I left the Times in UTC +2 (I’m UTC / GMT). See attached.
I’ll check it out more now.
Thank You
GraHal
I haven’t studied / understood the code (got one eye on the TV! 🙂 ) but I noted the poor performance during a flat period so I added conditions re EMA as shown below.
Results improved to the upper equity curve attached.
GraHal
//https://www.prorealcode.com/topic/consecutive-bullish-or-bearish-candlesticks-dax/-------------------------------------------------------------------------
//PRC_TS multiple candlesticks | indicator
//01.03.2017
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
//This is not my code.
//Original code was written and published by Sir.Nicolas
//-------------------------------------------------------------------------
// Prevents the system from creating new orders to enter the market or increase position size before the specified time
noEntryBeforeTime = 070000//070000 //UTC +2
timeEnterBefore = time >= noEntryBeforeTime
// Prevents the system from placing new orders to enter the market or increase position size after the specified time
noEntryAfterTime = 190000//190000 //UTC +2
timeEnterAfter = time < noEntryAfterTime
// --- parameters
Size = 2 //position size
StopLoss = 40 //stoploss in points
TakeProfit = 20 //takeprofit in points
Xcandlesticks = 4 //consecutive bullish or bearish candlesticks to open a new position
InverseTrading = 0 //(0=false ; 1=true) trade in the same direction of the candlesticks pattern or not
CumulateOrder = 1 //(0=false ; 1=true) cumulate or not a new trade if the current candlestick is in the same trend as the pattern
// ------------
//detecting patterns
bearpattern = summation[Xcandlesticks](close<open)=Xcandlesticks
bullishpattern = summation[Xcandlesticks](close>open)=Xcandlesticks
//first order
if not onmarket and timeEnterBefore and timeEnterAfter then
if bearpattern and Close < ExponentialAverage[200](close)then
if InverseTrading and Close < ExponentialAverage[100](close) then
BUY Size CONTRACTS AT MARKET
else
SELLSHORT Size CONTRACT AT MARKET
endif
lastbar = barindex
lastpattern = -1
endif
if bullishpattern and Close > ExponentialAverage[175](close) then
if InverseTrading and Close > ExponentialAverage[100](close) then
SELLSHORT Size CONTRACT AT MARKET
else
BUY Size CONTRACTS AT MARKET
endif
lastbar = barindex
lastpattern = 1
endif
endif
//cumulate order when a new pattern occurred
if onmarket and timeEnterBefore and timeEnterAfter and not CumulateOrder and barindex-lastbar>=Xcandlesticks then
if bearpattern and Close < ExponentialAverage[100](close) then
if InverseTrading and Close < ExponentialAverage[100](close) then
BUY Size CONTRACTS AT MARKET
else
SELLSHORT Size CONTRACT AT MARKET
endif
lastbar = barindex
endif
if bullishpattern and Close > ExponentialAverage[175](close) then
if InverseTrading and Close > ExponentialAverage[100](close) then
SELLSHORT Size CONTRACT AT MARKET
else
BUY Size CONTRACTS AT MARKET
endif
lastbar = barindex
endif
endif
//cumulate order when a new consecutive candletick happen right after the pattern occurred
if onmarket and timeEnterBefore and timeEnterAfter and CumulateOrder and barindex-lastbar=1 then
if longonmarket then
if (close>open and lastpattern=1) or (close<open and lastpattern=-1) then
BUY Size CONTRACTS AT MARKET
lastbar = barindex
endif
endif
if shortonmarket then
if (close>open and lastpattern=1) or (close<open and lastpattern=-1) then
SELLSHORT Size CONTRACT AT MARKET
lastbar = barindex
endif
endif
endif
SET STOP PLOSS StopLoss
SET TARGET PPROFIT TakeProfit
//END
Thanx for the code. It is perhaps interesting to code with heikin hashi candles instead of common candles. I’ll try later.
Grahal.
Thank you for your input. Appreciated.
I will definately try it.
I tried and tested this MultipleCandle code on almost all FX and Indices with various permutations and this code on US Russel 2000 was about the only profitable one.
I tried others with MFE code from Nicolas but those are not as profitable.
With your addition to this code other FX and Indices permutations I tried might just might become profitable.
Thank you.
Hi,
I confirm that backtests are better with heikin hashi for “bearpattern” and “bullishpattern”:
xClose = (Open+High+Low+Close)/4
if(barindex>2) then
xOpen = (xOpen[1] + xClose[1])/2
endif
//detecting patterns
bearpattern = summation[Xcandlesticks](Xclose<Xopen)=Xcandlesticks
bullishpattern = summation[Xcandlesticks](Xclose>Xopen)=Xcandlesticks
I have tested only DAX and CAC and found better results with DAX.
Hi @
noisette , please could you share the full code with your
heikin ashi for “bearpattern” and “bullishpattern”:
I added / changed as per your changes above … both to Andre code and to Andre code with my changes (addition of EMA) and I got the results attached. (from bottom up on equity curves)
I both cases worse results. Your full code will establish if I have made the changes incorrectly? Please also might you show the equity curve you got?
Thank You
GraHal
PS I added your code as shown attached … as replacement for lines 27 to 33
Hi GraHal,
Sorry, I used your code but I forgot to say that I worked with main modifications bellow:
- 3 consecutive candles instead of 4 (Xcandlesticks = 3).
- EMA 10 instead of your different values.
- SL 20 & TP 40.
- No overnight.
- Starting at 9am, last trade at 5.30pm, close at 11pm.
We probably could improve the code with other indicator instead of EMA.
Results seems to be also with other timeframes.
I’ll share the code when I’ll be at home.
Regards.