Nicolas

Multiple consecutive candlesticks strategy

Category: Strategies By: Nicolas Created: March 2, 2017, 5:05 PM
March 2, 2017, 5:05 PM
Strategies
12 Comments
Multiple consecutive candlesticks strategy

Principle of multi-candle trading strategy:
The automated trading strategy expects X consecutive candles having the same direction to open a position.

Example: the chart has just formed 6 consecutive bulbs, and I want that at the opening of the 7th candle, the system automatically opens a trade short (with stop loss and take profit).

Parameters and Options:

  • Size of the position: in number of lots.
  • Stop loss: to determine how many pips / points of the entry price will be positioned the stop loss of an opened position.
  • Take Profit: To determine how many pips / points of the entry price will be positioned the take profit of an open position.
  • Number of candles to wait: to determine the number of consecutive candles having the same meaning to wait.
  • Trade inverse: true / false, this option allows you to choose whether the opening of the trade will be in the same direction or the reverse of the X consecutive candles.

Example: If the option is set to “False”, the system opens a purchase after X candles bullish. Conversely, if the option is set to “True”, the system then opens a sale after X candles bullish. In other words: on False, the system opens positions in the direction of the movement during formation. On True, the system opens positions against the trend of the movement being formed.

  • Trading accumulation: true / false, this option is used to fix whether the system should (or should not) open a new position if the spark plug X + 1 is also in the same direction as the previous X candles. Example: If the option is set to “False”, the system waits at least X candles after opening a new position. If the option is set to “True”, the system can then cumulate new positions directly to each subsequent candlestick.

Example 1 of the multi-candle system:
1/10 2/30 3/60 4/7 5 / True 6 / False This setting causes the system to wait 7 consecutive bullish or bearish candles to open a counter-meaning trade to the 8th candle. If this 8th candle also closes in the same direction as the previous 7 candles, the system does not open a new position at the opening of the 9th candle. * * Having already opened a position, the system waits again 7 consecutive candles From the 8th candle to possibly open a new position (if these candles from 8 to 14 are all in the same direction)

Example 2 of the multi-candle system:
1/10 2/30 3/60 4/3 5 / False 6 / True This setting means that the system expects 3 consecutive bullish or bearish candles to open a trade in the same direction to the 4th candle. If this 4th candle also closes in the same direction as the previous 3 candles, the system opens a new position directly at the opening of the 5th candle.

This trading strategy has been coded by a request on the French forum. Please consider that there is no typical settings and it is not dedicated to any instrument or timeframe at all. This strategy is almost like a “sandbox” for studying purpose and to define suitable parameters for your preferred instruments.

//PRC_TS multiple candlesticks | indicator
//01.03.2017
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge

// --- parameters
Size = 1 //position size
StopLoss = 20 //stoploss in points
TakeProfit = 10 //takeprofit in points
Xcandlesticks = 6 //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 = 0 //(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 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 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 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

 

Download
Filename: PRC_TS-multiple-candlesticks.itf
Downloads: 549
Nicolas
Nicolas Legend
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
Author’s Profile

Comments

Pring00
6 years ago
#

Hello @Nicolas, thanks for this code! Just what i was looking for. I'm fairly new to this but do you have any suggestions to implement a code that makes you able to set a certain close of the candlestick? Let's say i want 4 consecutive bullbars but i want all of them close 60% of the candlestick or higher

Nicolas
6 years ago
#

Needs custom coding, ask for a mod in a dedicated topic, in the appropriate forum please.

Jessar
7 years ago
#

Hi friends, is there any way to program the system to close the position when you have a longtrade an a bear candel is come ? thank you lg

triss1965@gmail.com
10 years ago
#

Hi, I dont understand, when I do the backtest I get only drawdown and a big loos? Have I missed something?

Francesco78
10 years ago
#

 Sorry I must add that it looks great only if we start the backtesting from 2008.

Im not familiar with the forum yet, I cant upload the image of the backtesting for some reason.

Apologies for this 

Nicolas
10 years ago
#

You can't upload images here, sorry.

Francesco78
10 years ago
#

Thank you Nicolas, great code, I have tried with the Bund future, with daily framework and the results look pretty amazing. 

//PRC_TS multiple candlesticks | indicator
//01.03.2017
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
// Stops and targets
// Stops and targets


// --- parameters
Size = 100 //position size
StopLoss = 25 //stoploss in points
TakeProfit = 60 //takeprofit in points
Xcandlesticks = 5 //consecutive bullish or bearish candlesticks to open a new position
InverseTrading = 1 //(0=false ; 1=true) trade in the same direction of the candlesticks pattern or not
CumulateOrder = 0 //(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 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 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 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 pTrailing StopLoss
SET TARGET PPROFIT TakeProfit

andre.vorster
10 years ago
#

Hello.

Great code.!

I’m just so amazed by your guys coding ability (I can’t code to save my life even though I’m in IT – but learning a lot from the masters here and learning myself)
Played with this code with various options across various commodities/FX and Indices.
Running this now on Gold-mini 1 £ on IG demo account. Looks promising so far.
From my back testing looks like this code is runs almost any time frame from 2min right up past 20min timescale.

Thank you.

lozano
10 years ago
#

Hello all and thanks for sharing scripts!

@Duck74: Did you try this scripts in real market?

David
10 years ago
#

I think it's important to note that the SET STOP pLOSS will not be a combined STOP LOSS if Cumulative = 0. Each trade will have it's own SET STOP pLOSS StopLoss.

Felix80
10 years ago
#

This is just that I was looking for!! Thanks a lot.

Duck74
10 years ago
#

Molto bello sui 15m da ottimi risultati !!!

ProRealCode ProRealCode
Loading...