EA with multiple BB

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #178890 quote
    cgassfr67
    Participant
    Senior

    Hello,

    I want to create a EA who trade off multiple Bollinger Band

    I have 3 BB

    The normal BB (50:2) (Average 50 -3*Standart Deviation)

    The seconde BB (50:3)

    And the last BB (50:4)

    I have also 2 more filter : Stochastic (14,3,3) and RSI(8)

    For an entry here are the rules

    The low =  inferior BB(50:3) & Stochastic (14,3,3) under 20 & RSI(8) under 30

    the stop loss is inferior BB(50:4), who don’t move.

    The exit rule is high = middle BB(50:2)

    Can please someone help me with that code ?

    I will share the results with all here

    Thank you

    #179197 quote
    robertogozzi
    Moderator
    Master

    There you go:

    DEFPARAM CumulateOrders = false
    //-------------------------------------------------------------------------
    //                          Bollinger Bands 1
    ONCE BBperiods1 = 50                                          //50   BB periods
    ONCE BBdev1     = 2.0                                         //2.0  BB deviation
    ONCE AvgType1   = 0                                           //0=sma, 1=ema, etc...
    BBavg1          = average[BBperiods1,AvgType1](close)         //BB mean (middle line)
    BollUP1         = BBavg1 + ((std[BBperiods1](close)) * BBdev1)//BB Upper Band
    BollDN1         = BBavg1 - ((std[BBperiods1](close)) * BBdev1)//BB Lower Band
    //-------------------------------------------------------------------------
    //                          Bollinger Bands 2
    ONCE BBperiods2 = 50                                          //50   BB periods
    ONCE BBdev2     = 3.0                                         //3.0  BB deviation
    ONCE AvgType2   = 0                                           //0=sma, 1=ema, etc...
    BBavg2          = average[BBperiods2,AvgType2](close)         //BB mean (middle line)
    BollUP2         = BBavg2 + ((std[BBperiods2](close)) * BBdev2)//BB Upper Band
    BollDN2         = BBavg2 - ((std[BBperiods2](close)) * BBdev2)//BB Lower Band
    //-------------------------------------------------------------------------
    //                          Bollinger Bands 3
    ONCE BBperiods3 = 50                                          //50   BB periods
    ONCE BBdev3     = 4.0                                         //4.0  BB deviation
    ONCE AvgType3   = 0                                           //0=sma, 1=ema, etc...
    BBavg3          = average[BBperiods3,AvgType3](close)         //BB mean (middle line)
    BollUP3         = BBavg3 + ((std[BBperiods3](close)) * BBdev3)//BB Upper Band
    BollDN3         = BBavg3 - ((std[BBperiods3](close)) * BBdev3)//BB Lower Band
    //-------------------------------------------------------------------------
    //                          Stochastic
    MyStoch         = Stochastic[14,3](close)
    //-------------------------------------------------------------------------
    //
    //                          Rsi
    MyRsi           = Rsi[8](close)
    //-------------------------------------------------------------------------
    // Entry conditions
    c1              = low     < BollDN2
    c2              = MyStoch < 20
    c3              = MyRsi   < 30
    // Exit  conditions
    d1              = high <= BBavg1
    //-------------------------------------------------------------------------
    // enter a position
    IF c1 AND c2 AND c3 AND Not LongOnMarket THEN
       BUY 1 CONTRACT AT Market
       SL = abs(close - BollDN3)
       SET STOP LOSS SL
    ENDIF
    // update Stop Loss according to TRADEPRICE (instead of close) when known
    IF LongOnMarket AND Not LongOnMarket[1] THEN
       SL = abs(TradePrice - BollDN3[1])
       SET STOP LOSS SL
    ENDIF
    // exit any open position
    IF d1 AND LongOnMarket THEN
       SELL AT Market
    ENDIF
    //
    //graphonprice TradePrice
    //graphonprice TradePrice - SL
    Midlanddave and cgassfr67 thanked this post
    #179991 quote
    cgassfr67
    Participant
    Senior

    Thank you very much Roberto.

    I will test and publish the result here

    #179993 quote
    cgassfr67
    Participant
    Senior

    Hello Roberto,

    I test the EA, but every trade in only on 0 or 1 minutes.
    The trade close right after entry.
    Here a snapshot of a single position

    The right order from this example is open at your entry, but the stop loss is on BB3 (yellow). And this entry, normally close after

    I hope that the snapshot will help

    Thank you

    Capture-decran-2021-10-19-a-23.17.25.png Capture-decran-2021-10-19-a-23.17.25.png Capture-decran-2021-10-19-a-23.22.47.png Capture-decran-2021-10-19-a-23.22.47.png
    #180170 quote
    robertogozzi
    Moderator
    Master

    Replace line 39 by:

    d1              = high >= BBavg1
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

EA with multiple BB


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
cgassfr67 @cgassfr67 Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by robertogozzi
4 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/01/2021
Status: Active
Attachments: 2 files
Logo Logo
Loading...