A Bollinger Flag. My small contribution

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
arjfca
Posts: 1273
Joined: 23 Nov 2010
Has thanked: 721 times
Been thanked: 222 times

A Bollinger Flag. My small contribution

Postby arjfca » 20 Jan 2011

Hello
Here is my small contrubution to the forum. An idea that i had around the Bollinger band.

A bollinger band is like a string of saussage. Expend for a while then retract. Good opportunity could be found when Bollinger band retract and trend toward the midline.

My idea was to quantify the period when price retract and period where they attract one each other.

If band turn toward the mid line, I had+1. When band repulse, I sustract -1. The value is then averaged over a given period and resullt is displayed

A green spot, Band attraction, Both Upper and Lower band in direction of the middlemine
A red Spot, Band repulse, Both Upper and Lower band repulse from the other one
A brown spot is when Upper and Lower Band are not in the same direction

What i found:
- An extended period in the Brown spot is a prelude for a move in one direction

- An undisturbed and extended period in the Green spot ( 5 and more) is not good at all . Price as lost a lot of energy and signal are mixed after. Better to wait for the signal to go in the Brown or red spots.

- A period less than 5 in the green spot or if the value = 1 combinned with a setup and timing tool show good opportunity

- A period of 5 and no more than 7 in red spot is a prelude for a counter trend mouvement. Price as extended too much and it want to take a pause.

Unfortunaly, I'm not able to take profit of the information given. If there is some genius that found an utility, or a way to define usable rules with it, please let me know.

Martin
Attachments
Boll_Flag.gif
Boll_Flag.gif (24.44 KiB) Viewed 531 times

arjfca
Posts: 1273
Joined: 23 Nov 2010
Has thanked: 721 times
Been thanked: 222 times

Re: A Bollinger Flag. My small contribution

Postby arjfca » 20 Jan 2011

Hello TJ

Thank. What i was looking was a way to code for period when i should nolook to be in trade. That was my first code that i create in MC

Here is the code
Be indulgent as i don't qualify as a professional hehe!

Code: Select all

{This indicator, base on Bollinger Bands, will display a line that will oscillate between two level, +1 and -1

Bollinger band move like opposite sinus.  It expand and retract from each other. 

This indicator will draw a green spot when Bollinger band retract toward each other.  This period may signify that the
actual trend is comming to the end.   New position should be entered during this retractation time
}

// Created by Martin Thriault
// January 05 2011
inputs:
BollingerPrice( Close ),
TestPriceUBand( Close ),
TestPriceLBand( Close ),
Length( 20 ),
NumDevsUp( 2 ),
NumDevsDn( -2 ),
AVG   (5),         //Average

NBPIn (3);         // How many periods signal as to be true before signaling a change
//Numperiodsout (3);     // How many periods signal as to be true before signaling a change

variables:
BollAverage (0),         // Bollinger Average
BollDeviation (0),       // Bollinger standart deviation
BollUp (0),          // Bollinger Upper band Value
BollDown (0),          // Bollinger band down Value
BolUpExpand ( false),       // Is the bollingerUp expand
BollDownExpand (False),   // Is the bollingerDown expand

NBPGreen (0),          // Number of periods... counter
NBPRed (0),
FlagGreen(False),   // Green Flag
FlagRed (False),      // Flag Red
FlagOrange (False),   // Flag Orange
Flag (Text),      // String varable
FlagValue (0),      // 2 fpr green // -1 for red
AverageFlag (0),
Color (0);


{ _____ End Of Variables_______________________________________________________________)

  _____ Start of coding _______________________________________________________________}
 
NBPGreen = NBPIn;
NBPRed = NBPIn;

If BarStatus = 2 then begin

   BollAverage = Averagefc( BollingerPrice, Length ) ;
   BollDeviation = StandardDev( BollingerPrice, Length, 1 ) ;
      BollUp  = BollAverage+ NumDevsUp *BollDeviation;
   BollDown = BollAverage + NumDevsDn * BollDeviation ;
     
      // Look for a retraction or attraction of the bands
      // For  retraction: BollUp will be higher than Bollup[1] and BollDown will be lower than BollUp
      // For attraction:  Bollup will be lower than Bollup[1] and BoolDown will be higher than BollDown[1]
     
      // Both conditions need to be effective for NumPeriodIn before being considered true
   
   // Attraction
      condition1 = Bollup < Bollup[1];
      Condition2 = BollDown > BollDown[1];

      If condition1 = true and condition2 = true then begin
          FlagGreen = true;
          Flag = "Green";
          FlagValue =1;
          averageflag = averageflag +1;
          FlagRed = false;
       end
       else begin
          NBPGreen  = NBPGreen -1;
          flaggreen = false;
       end;
 
      If condition1 = false and condition2 = false then
         begin
           flagred = True;
           Flag = "Red";
           Flagvalue = -1;
           averageflag =averageflag -1;
         End
      else begin
           FlagRed = False;
      end;
     
     
      If condition1 = False and condition2 = true then FlagOrange =true;
      If condition1 = True and condition2 = False then FlagOrange= true;
      //If FlagOrange then Flag = "Orange" ;
     
      If FlagGreen = True then begin
         flagred = false;
         flagorange = false;
         plot4(flagvalue,"Flag");
         setplotColor (4, Green);
       end;
       
       If FlagRed = True then begin
          flag = "orange";
          flaggreen = false;
          flagorange = false;
          Plot4(flagvalue,"Flag");
          Setplotcolor (4, Red);
        end ;
       
        If FLagorange = True then begin
           flaggreen = false;
           flagred = false;
           //flagvalue = flagvalue;
           
           Flagvalue = 0;
           Plot4(flagvalue, "Flag");
           SetPlotColor(4,RGB(224,160,32));
        end;
        //if flagvalue >=6 then flagvalue = flagvalue -.5;
        //if flagvalue <=6 then flagvalue = flagvalue +.5;
        plot5(Average( flagvalue,avg), "Av. Flag");
               
end;
   
   







User avatar
TJ
Posts: 6572
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 968 times
Been thanked: 1901 times

Re: A Bollinger Flag. My small contribution

Postby TJ » 20 Jan 2011

arjfca wrote:Hello TJ

Thank. What i was looking was a way to code for period when i should nolook to be in trade. That was my first code that i create in MC

Here is the code
Be indulgent as i don't qualify as a professional hehe!
...

Nice code. Thanks for sharing.

As in any technical analysis,
it is important to use a supplementary signal (eg multi-time frame, multi-resolution, etc.,) to support your trigger.

For starter, I would add a second moving average, maybe a 40~60 MA? (that's 2~3x the BB length).
That should filter out some of the "noise" in your signals.

arjfca
Posts: 1273
Joined: 23 Nov 2010
Has thanked: 721 times
Been thanked: 222 times

Re: A Bollinger Flag. My small contribution

Postby arjfca » 20 Jan 2011

Looking at your small drawing, combined with the green and red spot, I could get a better picture of the Bollinger stage.

Extended green: Contraction
Orange to red, : start for the expension
Extended red : Expention.... Don't counter trend
Red to Orange : Start to contraction
Extended Orange: Contraction or expension, stay alert.

Also visualy tested. A comparaison between green spot and the price level at witch they appeared seam to indicate the direction of the trend. Maybe not the best tool but...

Green spot: Price make a pause
Red spot: Price in the move

A pause level to the other pause level could be interpreted as a representation of the direction of the trend.

Martin

Merci TJ,
Your small contribution help me to get a better view whit this tool


Return to “User Contributed Studies and Indicator Library”