Consecutive bullish or bearish candlesticks – DAX

Viewing 15 posts - 1 through 15 (of 27 total)
  • Author
    Posts
  • #59824 quote
    Andre Vorster
    Participant
    Senior

    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)

    Yannick thanked this post
    DAX-1min-multiple-candle-001.jpg DAX-1min-multiple-candle-001.jpg DAX-1min-multiple-candle-002.jpg DAX-1min-multiple-candle-002.jpg DAX-1min-multiple-candle.xls
    #59920 quote
    Yannick
    Participant
    Veteran

    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

    DAX-1-minute.png DAX-1-minute.png DAX-1-minute-strategy.jpg DAX-1-minute-strategy.jpg
    #59924 quote
    GraHal
    Participant
    Master

    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

    #60242 quote
    Andre Vorster
    Participant
    Senior

    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.

    GraHal thanked this post
    #60309 quote
    GraHal
    Participant
    Master

    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

    #60344 quote
    Yannick
    Participant
    Veteran

    Hi

    Thanks @Andre Vorster

    Could share the graph or trade opened and strategy performance (evolution of equity versus time)?

     

    Regards

    #60361 quote
    Andre Vorster
    Participant
    Senior

    Yannick.

    I’m not sure I understand your question correct.
    Can you please elbaborate.

    #60443 quote
    Yannick
    Participant
    Veteran

    Hi Andre

    The profit /loss evolution of your real equity using this strategy.

    (similar to the backtested one that I linked)

    DAX-1-minute-1.png DAX-1-minute-1.png
    #60446 quote
    GraHal
    Participant
    Master

    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

    Andre2.jpg Andre2.jpg Andre.jpg Andre.jpg
    #60455 quote
    GraHal
    Participant
    Master

    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
    
    Nicolas, Yannick and noisette thanked this post
    Andre3.jpg Andre3.jpg
    #60465 quote
    noisette
    Participant
    Veteran

    Thanx for the code. It is perhaps interesting to code with heikin hashi candles instead of common candles. I’ll try later.

    Nicolas thanked this post
    #60466 quote
    Andre Vorster
    Participant
    Senior

    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.

    GraHal, Nicolas and Yannick thanked this post
    #60652 quote
    noisette
    Participant
    Veteran

    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.
    GraHal thanked this post
    #60682 quote
    GraHal
    Participant
    Master
    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
    Andre4.jpg Andre4.jpg Andre5.jpg Andre5.jpg
    #60686 quote
    noisette
    Participant
    Veteran
    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.
    GraHal thanked this post
Viewing 15 posts - 1 through 15 (of 27 total)
  • You must be logged in to reply to this topic.

Consecutive bullish or bearish candlesticks – DAX


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 26 replies,
has 6 voices, and was last updated by mcosta
8 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/18/2018
Status: Active
Attachments: 23 files
Logo Logo
Loading...