Hello,
Recently my friend, who is a candlesticks' enthusiast (and likes to test and look for different patterns in several less popular intervals), asked me if it would be possible to change chart's interval using chart parameter's slider. I knew it is doable and wrote a simple code allowing to do that. Because I thought that it might be also useful for other users, here it is:
_SECTION_BEGIN( "Custom Chart Interval v 1.0" );
// By Milosz Mazurkiewicz
/// @link https://forum.amibroker.com/t/changing-charts-interval-using-chart-parameters-slider/8795/1
MyIntervalT = Param( "Custom interval in Ticks", 0, 0, 500, 1 );
MyIntervalS = Param( "Custom interval in Seconds", 0, 0, 60, 1 );
MyIntervalM = Param( "Custom interval in Minutes", 0, 0, 60, 1 );
MyIntervalH = Param( "Custom interval in Hours", 0, 0, 24, 1 );
MyIntervalD = Param( "Custom interval in Days", 1, 0, 251, 1 );
MyIntervalR = Param( "Custom Range Bars", 0, 0, 100, 1 );
MyIntervalV = Param( "Custom Volume Bars", 0, 0, 50000, 50 );
if( MyIntervalT != 0 ) MyInterval = MyIntervalT * -1 ;
else
if( MyIntervalV != 0 ) MyInterval = -2000000 - MyIntervalV ;
else
if( MyIntervalR != 0 ) MyInterval = -1000000 - MyIntervalR ;
else MyInterval = MyIntervalD * inDaily + MyIntervalH * inHourly + MyIntervalM * in1Minute + MyIntervalS * in1Second;
if( Nz( StaticVarGet( "LastInterval" ) ) != MyInterval AND MyInterval != 0 )
{
AB = CreateObject( "Broker.Application" );
doc = AB.ActiveDocument;
doc.Interval = MyInterval;
StaticVarSet( "LastInterval", MyInterval );
}
Above solution might be useful for the users sharing similar approach to my friend, wanting to quickly and easily test their indicators in several, custom intervals. Of course I'm not saying, that entering 3m or 3h or 300V in the interval Box and hitting Enter
or clicking an appropriate shortcut is a big effort - of course it's not - it's very handy, but if someone wants to quickly browse through several (sometimes only slightly different intervals), using a slider for that might be an interesting alternative. It might also help to realize that a very strict or rigorous approach to patterns is not always the best idea, because if some setup or pattern looks very bullish in 5 minute timeframe, it might look a lot different when the TF is switched to e.g. 4 or 6 minutes.
In this version it allows to change chart's interval to n ticks, seconds, minutes, hours, days, range bars or volume bars. Weekly, monthly or yearly interval can also be easily added. It is worth noting, that if someone wants to change interval to n Ticks or to range bars (for the best results), database should use Tick as Base Time Interval.
Because it uses OLE instead of TimeFrameMode()
and TimeFrameSet()
, it should be used with caution in case of AFLs making use of those two functions.
One of the advantages of this approach - when comparing to using TimeFrameMode()
and TimeFrameSet()
is the fact, that it changes the interval of the whole chart window with all it's panes and different indicators in one go.
Another advantage is the fact, that using this code, someone can still change the chart's interval manually in any other way - it won't interfere.
To display range charts, first you need to specify the TickSize in the Symbol–>Information window:
http://www.amibroker.com/kb/2014/09/19/how-to-display-range-bars/
I used some ideas from Tomasz's code:
Additional reading:
https://www.amibroker.com/guide/afl/timeframemode.html
https://www.amibroker.com/guide/afl/timeframeset.html