Formula for BreakOut of Bollinger Bands in Daily and Weekly

I was looking for a formula that would give me the Break Outs of Bollingeur Bands (BB) in Daily(D) and Weekly(W). Finding nothing to my liking, I wrote one.

In an upward wave, we often have several BB Brake Outs.

To overcome this problem I added the Stockastic Crossing to my formula

Cross(StochK(9,3),StochD(9,3,3))

On a daily(D) graph, we have the result:

The BB BreakOut in daily: function BrOutBb(P) in orange

And the BB BreakOut in weeklyk: BrOutBb_W(15) in blue and orange on a TF weekly(W)

The function BrOutBb(P)- orange gives me the BrOutdeBB on the Time Frame(TF) that we have on the screen (D or W) and I like their result. Whether it’s a daily(D) or a weekly(W).

The BrOutBbW-in blue, on the TF daily is very disappointing.

I am open to any comments to do better.

THANKS

Yves Laliberté
````Code button (use to enter/paste AFL formula)`
_SECTION_BEGIN("CrBB Week In Daily de base");
/* Test pour les BraakeOut de BB en jour et semaine */
function BBT(P) { bon= BBandTop(C,P,2) ; return bon ; } ;
function CrBBT(P) { bon= Cross(C,BBT(P)) ; return bon ; } ;
MaxP= BarsSince(Cross(StochK(9,3),StochD(9,3,3)) AND LLV(StochK(9,3),3)<=20) ;
function BrOutBb(P)
{bon= IIf( CrBBT(P) AND Ref(BarsSince(CrBBT(P))>MaxP,-1) , 1 ,0 ) ;
Bon= IIf(Bon==1,2,0) ; return Bon ; }

Plot( BrOutBb(15),"BrOutBB-D",colorOrange,styleOwnScale );

TimeFrameSet( inweekly ); // switch now to week
MaxPW= BarsSince(Cross(StochK(9,3),StochD(9,3,3)) AND LLV(StochK(9,3),3))<=20 ;
function BrOutBb_W(P)
{bon= IIf( CrBBT(P) AND Ref(BarsSince(CrBBT(P))>MaxPW,-1) , 1 ,0 ) ;
Bon= IIf(Bon==1,2,0) ; return Bon ; }
Br= BrOutBb_W(15) ;
TimeFrameRestore(); // restore time frame to original
BrOutBbW= TimeFrameExpand( Br, inWeekly) ;

Plot( BrOutBbW,"BrOutBB-W",colorBlue,styleOwnScale );

_SECTION_END();
2024-01-31T05:00:00Z