Bollinger Bandit

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #84108 quote
    achel
    Participant
    Average

    The Bollinger Bandit uses one standard deviation above the 50-day moving average as a potential long entry and one standard deviation below the 50-day moving average as a potential short entry.
    The longer that we are in a trade, the easier it is to exit the market with a profit. We keep decrementing the number of days in our moving average calculation until we reach ten. From that point on, we do not decrement. There is one more element to our exit technique: the moving average must be below the upper band if we are long and above the lower band if we are short.
    This element is to prevent the system from going back into the same trade that we just liquidated. If we hadn’t used this additional condition and we were long and the moving average was above the upper band, the long entry criteria would still be set up and a long trade would be initiated.
    One more test must be passed before we initiate a position; the close of today must be greater than the close of 30 days ago for a long position and the close of today must be less than the close of 30 days ago for a short position. This additional requirement is a trend filter. We only want to go long in an uptrend and short in a downtrend.
    This system is longer term in nature, so we will use 50 days in our calculations.
    Could someone please translate into PRC code ? Thanks

    ———————————-
    Bollinger Bandit Pseudocode
    LiqDay is initially set to 50
    upBand = Average(Close,50) + StdDev(Close,50) *1.25 dnBand = Average(Close,50) – StdDev(Close,50) *1.25 rocCalc = Close of today – Close of thirty days ago

    Set liqLength to 50
    If rocCalc is positive, a long position will be initiated when today’s market action >= upBand
    If rocCalc is negative, a short position will be initiated when today’s market action <= dnBand
    liqPoint = Average(Close, 50)
    If liqPoint is above the upBand, we will liquidate a long position if today’s market action <= liqPoint If liqPoint is below the dnBand, we will liquidate a short position if today’s market action >= liqPoint
    If we are not stopped out today, then liqLength = liqLength – 1 If we are stopped out today, then reset liqLength to fifty
    —————————————-BELOW -TO TRANSLATE——————————————————–
    Bollinger Bandit Program
    {Uses Bollinger Bands and Rate of change to determine entry points. A trailing stop that is proportional with the amount of time a trade is on is used as the exit technique.}

    Inputs: bollingerLengths(50),liqLength(50),rocCalcLength(30); Vars: upBand(0),dnBand(0),liqDays(50),rocCalc(0);
    upBand = BollingerBand(Close,bollingerLengths,1.25); dnBand = BollingerBand(Close,bollingerLengths,-1.25);

    rocCalc = Close – Close[rocCalcLength-1]; {remember to subtract 1} if(MarketPosition <> 1 and rocCalc > 0) then Buy(“BanditBuy”)tomorrow upBand
    stop;
    if(MarketPosition <>-1 and rocCalc < 0) then SellShort(“BanditSell”) tomorrow dnBand stop;

    if(MarketPosition = 0) then liqDays = liqLength; if(MarketPosition <> 0) then
    begin
    liqDays = liqDays – 1;
    liqDays = MaxList(liqDays,10);

    end;
    if(MarketPosition = 1 and Average(Close,liqDays) < upBand) then Sell(“Long Liq”) tomorrow Average(Close,liqDays) stop; if(MarketPosition = -1 and Average(Close,liqDays) > dnBand) then BuyToCover(“Short Liq”) tomorrow Average(Close,liqDays) stop;

    ———————————-THANKS—————————————–

    #84109 quote
    swapping
    Participant
    Master

    bonjour achel, il serais bien que tu t’exprime en Français sur le forum français

    par avance merci et bon week end

    Nicolas thanked this post
    #84115 quote
    Nicolas
    Keymaster
    Master

    Topic moved to automatic trading forum (ProOrder) and in the English section.

    #84147 quote
    Nicolas
    Keymaster
    Master

    Here is the translated code for ProOrder:

    defparam cumulateorders=false
    
    bollingerLengths=50
    liqLength=50
    rocCalcLength=30
    
    avg = average[bollingerLengths]
    upBand = avg+std[bollingerlengths]*1.25
    dnBand = avg-std[bollingerlengths]*1.25
    
    rocCalc = Close - Close[rocCalcLength-1]// {remember to subtract 1} 
    if(not longonmarket and rocCalc > 0) and close<upBand then 
    Buy 1 contract at upBand stop 
    endif
    if(not shortonmarket and rocCalc < 0) and close>dnBand then 
    SellShort 1 contract at dnBand stop
    endif
    
    if not onmarket then 
    liqDays = liqLength
    else
    liqDays = liqDays - 1
    liqDays = Max(liqDays,10)
    endif
    
    
    if(longonmarket = 1 and Average[liqDays] < upBand) then 
    Sell at Average[liqDays] stop
    endif
     if(shortonmarket = -1 and Average[liqDays] > dnBand) then 
    exitshort at Average[liqDays] stop
    endif

    What timeframe and instrument suits the best the strategy? For what purpose it was designed for?

    GraHal thanked this post
    #84166 quote
    GraHal
    Participant
    Master

    What timeframe and instrument suits the best the strategy?

    Attached is DAX 1 hour over 100k bars with spread = 2

    Boll-Bandit.jpg Boll-Bandit.jpg Boll-Bandit-1.jpg Boll-Bandit-1.jpg
    #84171 quote
    Nicolas
    Keymaster
    Master

    There was a mistake in the previous code, please use this one instead!

    defparam cumulateorders=false
    
    bollingerLengths=50
    liqLength=50
    rocCalcLength=30
    
    avg = average[bollingerLengths]
    upBand = avg+std[bollingerlengths]*1.25
    dnBand = avg-std[bollingerlengths]*1.25
    
    rocCalc = Close - Close[rocCalcLength-1]// {remember to subtract 1} 
    if(not longonmarket and rocCalc > 0) and close<upBand then 
    Buy 1 contract at upBand stop 
    endif
    if(not shortonmarket and rocCalc < 0) and close>dnBand then 
    SellShort 1 contract at dnBand stop
    endif
    
    if not onmarket then 
    liqDays = liqLength
    else
    liqDays = liqDays - 1
    liqDays = Max(liqDays,10)
    endif
    
    
    if(longonmarket and Average[liqDays] < upBand) then 
    Sell at Average[liqDays] stop
    endif
     if(shortonmarket and Average[liqDays] > dnBand) then 
    exitshort at Average[liqDays] stop
    endif
    #84248 quote
    achel
    Participant
    Average

    The Bollinger Bandit program demonstrates how to:

    •  Invoke the Bollinger Band function. This function call is less than intuitive and must be passed three parameters: (1) price series, (2) number of elements in the sample used in the calculation for the standard deviation, and (3) number of deviations above/below moving average. You must use a negative sign in the last parameter to get the band to fall under the moving average.
    • Invoke the MaxList function. This function returns the largest value in a list.
    • Do a simple rate of change calculation.
    • Create and manage a counter variable, liqLength.

     

    • Could it be possible for you to backtest with above parameters one or more of the equities listed on attached table ?
    • Could it be possible to create an indicator fo a manual trading process ?
    • Thanks very much
    • BR
    Bol_Ban.png Bol_Ban.png
    #84307 quote
    Nicolas
    Keymaster
    Master

    Could it be possible for you to backtest with above parameters one or more of the equities listed on attached table ?

    I think that you’ll be able to do it by yourself?

    Could it be possible to create an indicator fo a manual trading process ?

    Do you mean an indicator with buy/sell signals on the price chart and with the strategy described in your first post?

    #84317 quote
    achel
    Participant
    Average

    Yes

    Is this possible ?

    #84328 quote
    Nicolas
    Keymaster
    Master

    Let’s try this:

    bollingerLengths=50
    liqLength=50
    rocCalcLength=30
    
    avg = average[bollingerLengths]
    upBand = avg+std[bollingerlengths]*1.25
    dnBand = avg-std[bollingerlengths]*1.25
    
    atr = AverageTrueRange[14](close)
    rocCalc = Close - Close[rocCalcLength-1]// {remember to subtract 1}
    if(lastsignal<=0 and rocCalc > 0) and close<upBand then
    drawarrowup(barindex,low-atr) coloured(0,255,0)
    lastsignal=1
    //lastbar=barindex
    endif
    if(lastsignal>=0 and rocCalc < 0) and close>dnBand then
    drawarrowdown(barindex,high+atr) coloured(255,0,0)
    lastsignal=-1
    //lastbar=barindex
    endif
    
    if lastsignal=0 then
    liqDays = liqLength
    else
    liqDays = liqDays - 1
    liqDays = Max(liqDays,10)
    endif
    
    
    //if(lastsignal=1 and Average[liqDays] < upBand) and barindex-lastbar>=1 then
    //drawtext("◄",barindex,upBand,dialog,bold,24) coloured(200,154,96)
    //lastsignal=0
    //endif
    //if(lastsignal=-1 and Average[liqDays] > dnBand) and barindex-lastbar>=1 then
    //drawtext("◄",barindex,upBand,dialog,bold,24) coloured(200,154,96)
    //lastsignal=0
    //endif
    
    return
    GraHal and RubberToe thanked this post
    #84344 quote
    achel
    Participant
    Average

    Thanks Nicolas

    This looks awesome

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.

Bollinger Bandit


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
achel @achel Participant
Summary

This topic contains 10 replies,
has 4 voices, and was last updated by achel
7 years, 3 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/04/2018
Status: Active
Attachments: 3 files
Logo Logo
Loading...