Print Page | Close Window

3-bar breakouts

Printed From: BullCharts Forum
Category: BullCharts
Forum Name: BullScript
Forum Discription: Technical discussion related specifically to the BullScript programming language.
URL: http://www.bullcharts.com.au/forum/forum_posts.asp?TID=514
Printed Date: 10 Jun 2026 at 4:43am
Software Version: Web Wiz Forums 9.69 - http://www.webwizforums.com


Topic: 3-bar breakouts
Posted By: peter1
Subject: 3-bar breakouts
Date Posted: 12 Nov 2008 at 1:30pm

I have been trying to learn a little Bullscript by creating a simple buy/sell indicator.
The buy marker displays when price crosses the highest price of the previous 3 bars and the sell marker displays when price crosses below the lowest price of the previous 3 bars.
This seems to be working properly and now I would like to declutter the chart by making the redundant signals invisible. There doesn't seem to be a handy function for this in Bullscript. I believe Amibroker has a function called "exrem" that can be used for this purpose.
Would anyone like to share how they do this or give me some ideas please.

---------------------
My next task is to create a ribbon based on this indicator. The plan is to display this ribbon using a higher timeframe than the timeframe of the chart. eg I want to look for the buy signals on a weekly chart when the last signal in the monthly ribbon was a buy. I know how to mange the timeframe in the ribbons using the advanced menu tab.

There is a similar issue with the ribbon in that the displayed colors default to white when a signal has not occured (inside bars). This creates a tricolored ribbon instead of a bicoloured ribbon and looks unclear. 

Would someone like to suggest any ideas to fix this please.

 

 




Replies:
Posted By: rcameron
Date Posted: 21 Nov 2008 at 6:48pm
If you don't want to show the markers just double click on the markers on the chart and under Style de-select the marker icon. It can be turned on again by selecting the indicator in the header of the chart and selecting the marker icon again. This will hide all markers but I think you want to selectively only show the most recent markers, sorry can't help on this one. What about changing the size of the marker under 'Style' to de-clutter?
 
When coding the ribbon set a colour to reflect the satisfaction of the criteria, say [color=green] when the breakout occurs and then add [color=red] at the end of the code to define the default colour. I think my example below should help.
 

[color=green; name=Bullish]

[fillstyle=solid]

value1-value2>=0;

[color=red; name=Bearish]

[fillstyle=solid]

value1-value2<0;

[color=red]



Posted By: maximo
Date Posted: 25 Nov 2008 at 2:03pm
Hi Peter,
 
If you just want to display the lastest signal/marker? you can use Lastvalue(Barnumber) function to return the current barnumber and get your script to only check for your criteria on the most recent bar or a few bars from the recent bar, so previous signals will disappear as the chart updates while any new one will be displayed.
 
 
Here's a Trend Ribbon which only colours long or short.  You can adapt it to your signal.
 

{ Momentum Trend Ribbon }

[target=Ribbon]

MBO:=Ma(C,25,S) - Ma(C,200,S);

{ Trend detection based on new Highs & Lows of Momentum Oscillator }

Condition1:=hhv(MBO,89) > ref(hhv(MBO,89),-1) or llv(MBO,89) > ref(llv(MBO,89),-1);

Condition2:=llv(MBO,89) < ref(llv(MBO,89),-1) or hhv(MBO,89) < ref(hhv(MBO,89),-1);

Signal:= If(Condition1 = True, 1,If(Condition2 = True, -1, prev));

[color=rgb(98,217,98)] Signal=1

[color=rgb(226,118,118)] Signal=-1

    


Posted By: peter1
Date Posted: 26 Nov 2008 at 3:57pm
Thanks for replying.
My first query was how to make the redundant signals invisible. You can see the redundant signals in the chart. [ I think I might have posted an image!]
 
 
 


Posted By: peter1
Date Posted: 26 Nov 2008 at 4:35pm
Maximo (you legend), your suggestions worked a treat.
Here is the ribbon with the indicator.


Posted By: maximo
Date Posted: 27 Nov 2008 at 12:38am

Aha! now remove the redundant signals.   It was on my to do list for a while.. 

Increase breakout period for fewer trades & generally larger trends. 

[Description="Breakout Signals"]

[Target=Price]

n := input("Breakout period",3,0);

SignalLong := if(High > hist(HHV(H,n),1),1,0);

SignalShort := if(Low < hist(LLV(L,n),1),1,0);

SigLong := if(SignalLong,1,if(SignalShort,0,prev));

SigShort := if(SignalShort,1,if(SignalLong,0,prev));

[linestyle=marker; marker=long; name=""]

If(SigLong and SigLong <> hist(SigLong,1),1,0);

[linestyle=marker; marker=short; name=""]

If(SigShort and SigShort <> hist(SigShort,1),1,0);



Posted By: peter1
Date Posted: 27 Nov 2008 at 11:36am
Maximo - well done. Clap
 
Here are the results of your code (unaltered).


Posted By: peter1
Date Posted: 27 Nov 2008 at 11:49am
"Increase breakout period for fewer trades & generally larger trends."
 
A good observation and a valid suggestion. This technique works best in a trending instrument. You should see the signals on the crude oil chart. Forex works well also.
Stocks require additional filters, index trend filter, stock trend filter, volatility filters etc.
 
Next difficulty and it deals with the chart timeframes.
I can get set this ribbon to weekly and change the chart to daily. No problem.  The idea is to take the daily setups that are in sync with the weekly signals.
 
I am unable to set the ribbon to monthly and view the weekly chart with the monthly ribbon. The ribbon changes to weekly and ignores the convert to monthly command. Is this me or a Bullcharts problem? 


Posted By: peter1
Date Posted: 27 Nov 2008 at 12:02pm
For those interested, here are the signals on the crude oil weekly chart.


Posted By: peter1
Date Posted: 27 Nov 2008 at 12:13pm
It just occured to me that the inability to see the monthly ribbon on a weekly chart may be due to a conflict with the dates. A monthly timeframe can start /end within a weekly period and this might cause a conflict within Bullcharts.


Posted By: maximo
Date Posted: 27 Nov 2008 at 12:20pm
Good work Peter!
 
The crude oil chart  works well with the 3 line break :)
I can only suggest that multiplying your signal period by 5 (days/bars) in a week to overlay a weekly perspective should work.
 
I fiddled with the ribbon code and came up with a shorter version of no redundant signals.
Don't ask me why bullscipt allows redefining of the Signal variable as I have no idea..

[Description="Breakout Signals"]

[Target=Price]

n := input("Breakout periods",5,0);

SigLong := High > hist(HHV(H,n),1);

SigShort := Low < hist(LLV(L,n),1);

Signal:= If(SigLong = True,1,If(SigShort = True,-1,prev));

[linestyle=marker; marker=long; name=""]

If(hist(Signal,1)<>1,Signal=1,undefined);

[linestyle=marker; marker=short; name=""]

If(hist(Signal,1)<>-1,Signal=-1,undefined);



Posted By: peter1
Date Posted: 27 Nov 2008 at 12:29pm
[Excuse my repeated posts, but the SPI is going sideways and Maximo has me thinking.]
 
One idea how you might use these signals as part of a strategy.
The larger timeframe indicates the trend and the lower timeframe is used for entries and exits.
 


Posted By: peter1
Date Posted: 27 Nov 2008 at 12:44pm
We could include another input variable so that we can alter the entry and exit breakout signals.
eg. Entry signal is done on 3 bar breakout with exit done using 2 bar breakout.
 
This leads me to contemplate using an atr breakout instead of (or with) a 3 bar breakout. We could then define the breakout as a move greater than 2 x atr(10) from a pivot low or pivot high.
 
[PS. This forum may be at the top of the endangered species list but there is still some life in it. ]


Posted By: maximo
Date Posted: 27 Nov 2008 at 12:46pm

Yes I see going only with the longer term trend is usally more profitable than going against it.  ie. only take a position when your ribbon confirms.   No long positions were confirmed so the probability is better for the short side trades at the moment.      

Also agree that increased price volatility often preceeds a change  in trend.   Guppy has his momentum minute entries based on increased volatility, largest bar size/range in N bars. 
 
Originally posted by peter1

 We could then define the breakout as a move greater than 2 x atr(10) from a pivot low or pivot high.
 
Could add some kind of ATR line for this based on the highs & lows.   


Posted By: maximo
Date Posted: 27 Nov 2008 at 4:51pm

Hmm I see Jim Berg has done the work for us in this area, so i will just tack it onto our indicator.     You can see his stoploss uses 2*atr(10) and this adds some risk management to it including earlier possible sign of reversal or entry into a new trend.   I've included paintbars so it looks pretty :P

[ps: get the paddles out.. the forum is flat lining]
 
 
[Description="Breakout Signals"]

[Target=Price]

n := input("Breakout periods",5,0);

SigLong := High > hist(HHV(H,n),1);

SigShort := Low < hist(LLV(L,n),1);

Signal:= If(SigLong = True,1,If(SigShort = True,-1,prev));

[linestyle=marker; marker=long; name=""]

If(hist(Signal,1)<>1,Signal=1,undefined);

[linestyle=marker; marker=short; name=""]

If(hist(Signal,1)<>-1,Signal=-1,undefined);

[linestyle=pricecolor]

[color=rgb(98,217,98)] {lime green}

Signal=1;

[color=rgb(226,118,118)] {red}

Signal=-1;

[Description="Jim Berg vstop"]

al := input("ATR Period", 10, 1);

am := input("ATR Multiplier", 2, 0);

[linestyle=solid; name=Stop; color=Blue]

ts := hhv(C-am*ATR(al),15);

ts;



Posted By: peter1
Date Posted: 27 Nov 2008 at 9:44pm
You are getting fancy now with the TS and painted bars. Here is your latest work on the same chart.
 
[ps: All clear........ ker thunk.......  no pulse, increase the voltage and again....]


Posted By: peter1
Date Posted: 27 Nov 2008 at 9:48pm
Just noticed, that the colour coded bars makes the markers redundant.
It is also looking like the Tradeguider charts with their short term trending system turned on.


Posted By: peter1
Date Posted: 28 Nov 2008 at 2:34pm

Maximo: Thanks to your coding I have been able to modify the original 3barBO indicator.
The breakout marker is now based on a move greater than a multiple of an atr value.
  high >  (LLV of past 5 bars + 2*atr(10)) and the opposite for the sell trigger.

When you see the comparison with the original 3barBO ribbon you notice a slight improvement. Many small 3barBO's have not triggered the marker.

The next step is to display the buy/sell triggers on the chart but only over the last bar, so we can plan the weeks orders in advance.

Thank you for you input, Maximo. I hope you can appreciate how you made a huge contribution.

[ I can feel a weak pulse, put the forum in the intensive care unit and we will see if it recovers.]



Posted By: jalna
Date Posted: 28 Nov 2008 at 2:51pm
Hi Guys, terrific stuff. I have been following this thread with interest. Peter could you post the new formula please. Its looking good. I can't work out how to write even that
I have been waiting for Day to finish off the VSA code but he is too busy now as BC are changing servers.
I want to finish off the code so he is sending me a code example using the Icons BC already has available eg cross, arrows etc so look forward to getting that.
I wish i had a brain like Maximos, Maximo your the man


Posted By: peter1
Date Posted: 28 Nov 2008 at 3:15pm
[Hey Maximo, I detect another heart beat.]Smile
 
Hi Jalna, hope you are not looking for the "Holy Grail" indicator.  A solid understanding of VSA will serve you much better than any indicator.
This is still a work in progress and I may post formula when finished. 
Trading without a plan is a wealth hazard.
 
-----------------------
Fiddling with the parameter inputs allows me to select the optimal combo for each chart.
This combo shows breakouts based on price movement greater than 3*atr(10) from the High/Low of the past 10 bars.
 
You would have to agree this combo does a great job on this chart.
Don't mention the problems in over optimising. My trading experience will prevent that. This marker is just a tool.


Posted By: jalna
Date Posted: 28 Nov 2008 at 3:44pm
     Peter1 ,its ok. I'm way past the Holy Grail stage.
VSA is helpful, if i can combine that and EW I will be a happy girl. Learning , learning with some help.



Print Page | Close Window

Bulletin Board Software by Web Wiz Forums® version 9.69 - http://www.webwizforums.com
Copyright ©2001-2010 Web Wiz - http://www.webwiz.co.uk