Displaying Statistics on a Candlestick Chart

Hi

I'm hoping to display some simple statistics on my Candlestick chart but I'm struggling to find the best (most efficient) way of doing it. I'd like the statistics to be "running" statistics so that when I select a bar the statistics I see displayed on the chart represent values from the beginning of my data up to an including the selected bar.

As an example I've got some code that counts the number of double tops which I've placed into my chart AFL.

DoubleTop = High == Ref( High, -1 );
DoubleTopCount = Cum( DoubleTop );

If I insert the following line of code ...

SetBarsRequired( sbrAll, sbrAll );

... at the beginning of my chart AFL I get the correct number of double tops whenever I select a bar (up to that point in time). If I remove the line the value is incorrect. Now everywhere I've read suggests that I shouldn't use the SetBarsRequired( sbrAll, sbrAll ) if at all possible as it detracts from the benefits of QuickAFL. So, is there a better way to calculate accurate statistics and display them on my Candlestick chart without invoking the SetBarsRequired( sbrAll, sbrAll ) command?

Any ideas would be appreciated.

Thanks

Craig

That is true. As far I know to Count few events and then to Displaying Statistics on the chart , you need to say to AFL to read all past bars.

One way is to write a good AFL and store all your Statistics in static variables, and then run a Scan Analysis and then call the staticVars in your chart.

Or you can save it on a csv/txt file, then read the file and display it on the chart

If you want do all the calculation in the chart (Without AAnalysis), Yes you have to turnoff QuickAFL. with SetBarsRequired()

Sometimes it is painful to do A LOT of calculation in the chart with QuickAFL OFF, that’s why we have the scanner, exploration, backtest.

But all depended of how many condition you have in your mind to put in this AFL, and how smart is your code.

Just remember that you have to avoid to run this AFL, with Live intraday data.

After all if you still like to try, you MUST include few lines in your code. If you RUN ONCE all the calculation always is better. And for that use this code

RunOnce = ParamTrigger("Run Once", "Click here Once"); 

if(RunOnce) 
{ 
// your one-shot code here 
}

Also i like this code
How to run certain piece of code only once
http://www.amibroker.com/kb/2015/10/06/how-to-run-certain-piece-of-code-only-once/

2 Likes

Thanks PanoS

Might rethink what I'm trying to do and put it all into an Analysis. You've given me a few ideas to go on there. Appreciate you taking the time to reply.

Cheers

Craig