Does anyone have this AFL ?

pratapvb

Well-Known Member
#11
check this out to see if it meets your needs...just wrote this seeing this request. First bar will not work on the days that do not start at normal daily start time or prev trading day ends at a diff time than usual trading close time, like muhurat trading, or test trading on Saturdays, etc

_SECTION_BEGIN("TimeRemaining");
// Author: Pratap Balakrishnan
// email id: [email protected]
//
/*
Shows remaining time of the Last Bar
uses the time stamp of the last bar and previous bar to calculate so it should work independent of TF.
So for the 1st bar of the day adjustment is required as the prev bar is of the previous day.
It is also expected to accomodate for multiple holidays in between.
This adjustment factor is the difference between today's mkt start time and yday mkt end time in minutes.
This is adjustable in Parameters for differnt markets. Default is as per NSE equity mkt timings.
*/

daych = Day() != Ref(Day(), -1) ;
dt = DateTime() ;

Lastbardone = DateTimeDiff(dt[BarCount-1], dt[BarCount-2]) ;
Lastbarremain = Interval() - Lastbardone ;
fontsize = Param("Font Size", 14, 3, 100, 1) ;

GfxSelectFont( "Tahoma", fontsize , 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( ParamColor("Text Color", colorBlack) );
pxHeight = Status( "pxchartheight" ) ;
pxWidth = Status( "pxchartwidth");
dt_flag = 16 /*wordbreak*/;
textht = 200;

x = pxWidth - Param("from right edge", 150, 0, 1000, 1) ;
y = Param("From Top", 50, 0, 1000, 1) ;
firstbaradjust = Param("First Bar Adjust", 1065, 1, 100000, 1) ;

Lastbarremain =IIf(Daych, (Lastbarremain%inDaily)+(firstbaradjust*in1Minute),Lastbarremain) ;

Lastbarremain_min = int(Lastbarremain / in1Minute) ;
Lastbarremain_sec = Lastbarremain % in1Minute ;

GfxDrawText(NumToStr(Lastbarremain_min, 1.0)+" min "+NumToStr(Lastbarremain_sec, 1.0)+" sec", x,y, x+130, y+textht , dt_flag) ;
_SECTION_END();
 
Last edited:

trash

Well-Known Member
#12
Hey guys does any one have an afl which displays how time required to bar completion.
I have one that uses system time but its not too accurate.

Thx

ISA
AmiBroker has built in functions for bar completion

Look at Status function www.amibroker.com/guide/afl/status.html‎

- "lastbarend" - returns DateTime of the end of last bar. For example 5 -minute bar at 9:00 will have end time of 9:04:59 (works for time-based bars only) (v5.60)

- "lastbartimeleft" - returns number of seconds to the completion of current last bar. Works for time-based bars only. Note that for proper operation this requires database timeshift to be set properly (so dates displayed on chart match your local computer time zone). (v5.60)

- "lastbartimeleftrt" - it works like "lastbartimeleft" but uses the most recent RT stream update time instead of Now(). Also added Status("lastrtupdate") - time of last RT stream update depends on RT plugin to deliver correct DateUpdate / TimeUpdate data. If plugin or date source sends incorrect datetimestamps or does not send DateUpdate/TimeUpdate correctly this function will not operate properly. Note that most data sources send weird (not current) datetime stamps on weekends. Also IQFeed plugin sends DateUpdate/TimeUpdate only inside regular trading hours. (v5.60)

- "lastrtupdate" - returns date time of last update sent by RT plugin (see remarks above) (v5.60)


Since you wanna use it for realtime plugin you would have to use

Code:
Title = "Bar time left:" + Status( "lastbartimeleftrt" );
It returns {EMPTY} if there is no real-time source.
 
#13
check this out to see if it meets your needs...just wrote this seeing this request. First bar will not work on the days that do not start at normal daily start time or prev trading day ends at a diff time than usual trading close time, like muhurat trading, or test trading on Saturdays, etc

_SECTION_BEGIN("TimeRemaining");
// Author: Pratap Balakrishnan
// email id: [email protected]
//
/*
Shows remaining time of the Last Bar
uses the time stamp of the last bar and previous bar to calculate so it should work independent of TF.
So for the 1st bar of the day adjustment is required as the prev bar is of the previous day.
It is also expected to accomodate for multiple holidays in between.
This adjustment factor is the difference between today's mkt start time and yday mkt end time in minutes.
This is adjustable in Parameters for differnt markets. Default is as per NSE equity mkt timings.
*/

daych = Day() != Ref(Day(), -1) ;
dt = DateTime() ;

Lastbardone = DateTimeDiff(dt[BarCount-1], dt[BarCount-2]) ;
Lastbarremain = Interval() - Lastbardone ;
fontsize = Param("Font Size", 14, 3, 100, 1) ;

GfxSelectFont( "Tahoma", fontsize , 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( ParamColor("Text Color", colorBlack) );
pxHeight = Status( "pxchartheight" ) ;
pxWidth = Status( "pxchartwidth");
dt_flag = 16 /*wordbreak*/;
textht = 200;

x = pxWidth - Param("from right edge", 150, 0, 1000, 1) ;
y = Param("From Top", 50, 0, 1000, 1) ;
firstbaradjust = Param("First Bar Adjust", 1065, 1, 100000, 1) ;

Lastbarremain =IIf(Daych, (Lastbarremain%inDaily)+(firstbaradjust*in1Minute),Lastbarremain) ;

Lastbarremain_min = int(Lastbarremain / in1Minute) ;
Lastbarremain_sec = Lastbarremain % in1Minute ;

GfxDrawText(NumToStr(Lastbarremain_min, 1.0)+" min "+NumToStr(Lastbarremain_sec, 1.0)+" sec", x,y, x+130, y+textht , dt_flag) ;
_SECTION_END();
Hey This is great,
Thank you for you help really appreciate it.
It only displays 0 min n 0 sec, do I need to do some additional settings..

ISA.
 
#14
AmiBroker has built in functions for bar completion

Look at Status function www.amibroker.com/guide/afl/status.html‎

- "lastbarend" - returns DateTime of the end of last bar. For example 5 -minute bar at 9:00 will have end time of 9:04:59 (works for time-based bars only) (v5.60)

- "lastbartimeleft" - returns number of seconds to the completion of current last bar. Works for time-based bars only. Note that for proper operation this requires database timeshift to be set properly (so dates displayed on chart match your local computer time zone). (v5.60)

- "lastbartimeleftrt" - it works like "lastbartimeleft" but uses the most recent RT stream update time instead of Now(). Also added Status("lastrtupdate") - time of last RT stream update depends on RT plugin to deliver correct DateUpdate / TimeUpdate data. If plugin or date source sends incorrect datetimestamps or does not send DateUpdate/TimeUpdate correctly this function will not operate properly. Note that most data sources send weird (not current) datetime stamps on weekends. Also IQFeed plugin sends DateUpdate/TimeUpdate only inside regular trading hours. (v5.60)

- "lastrtupdate" - returns date time of last update sent by RT plugin (see remarks above) (v5.60)


Since you wanna use it for realtime plugin you would have to use

Code:
Title = "Bar time left:" + Status( "lastbartimeleftrt" );
It returns {EMPTY} if there is no real-time source.
Thanks very informative
 
#15
Ok I kinda figured something out,
lets say the default price code of Ami is

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

Suppose i need only the title, the current time frame Im trading in and finally the time / date, without the open close volume, which part of the above code would need to be deleted, without affecting the behaviour of price, candle, bar etc ?

Thax again for all your helpful replies ......

ISA
 

pratapvb

Well-Known Member
#16
Ok I kinda figured something out,
lets say the default price code of Ami is

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

Suppose i need only the title, the current time frame Im trading in and finally the time / date, without the open close volume, which part of the above code would need to be deleted, without affecting the behaviour of price, candle, bar etc ?

Thax again for all your helpful replies ......

ISA
replace everything from Open...onwards with ");

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}}") ;
 

pratapvb

Well-Known Member
#17
Hey This is great,
Thank you for you help really appreciate it.
It only displays 0 min n 0 sec, do I need to do some additional settings..

ISA.
It will show in Real time or in bar replay...at EOD the remaining time of last bar is 0-0

Note: I have not thorougly tested it in realtime...did some basic tests with bar replay....so in case you observe anything please let me know
 
Last edited:

trash

Well-Known Member
#18
Ok I kinda figured something out,
lets say the default price code of Ami is

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

Suppose i need only the title, the current time frame Im trading in and finally the time / date, without the open close volume, which part of the above code would need to be deleted, without affecting the behaviour of price, candle, bar etc ?

Thax again for all your helpful replies ......

ISA

Code:
_SECTION_BEGIN("Price");
SetChartOptions( 0, chartShowArrows | chartShowDates | chartWrapTitle );

bartime = Nz( Status( "lastbartimeleftrt" ) );
bartimestr = WriteIf( bartime == 0, "-> Datafeed OFF ", "-> %g seconds left " );
_N(Title = StrFormat( "{{NAME}} - " + EncodeColor( colorRed ) + "{{INTERVAL}} " + bartimestr + EncodeColor( colorDefault ) + "- {{DATE}} {{VALUES}}", bartime ) );

Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
 
Last edited:
#19
Code:
_SECTION_BEGIN("Price");
SetChartOptions( 0, chartShowArrows | chartShowDates | chartWrapTitle );

bartime = Status( "lastbartimeleftrt" ) / -21600;
bartimestr = WriteIf( bartime == 0, "-> Datafeed OFF ", "-> %g seconds left " );
_N(Title = StrFormat( "{{NAME}} - " + EncodeColor( colorRed ) + "{{INTERVAL}} " + bartimestr + EncodeColor( colorDefault ) + "- {{DATE}} {{VALUES}}", bartime ) );

Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
Hey thats really kewl !

Thx
 

Similar threads