And logic to color the background was also covered a long time ago in this KB article (see the last part of the formula).
You simply have to adapt it to your chart interval.
Speaking of AmiBroker Knowledge Base (aka KB): I personally believe that anyone who really wants to learn to program in AFL should carefully study all the articles that have been published there (scrolling the entire "Archives" calendar to the right). They are a treasure trove of knowledge!
I saw this KB but the problem is not working using dates, right?
tn = TimeNum();
// define start/end hours in TimeNum format
//StartTime = 93000;
//Endtime = 113000;
// these conditions are true when TimeNum of the bar equals startime/endtime
//StartBar = tn == StartTime;
//EndBar = tn == Endtime;
// my code
start = ParamDate( "START", "2001-01-01" );
end = ParamDate( "END", "2002-01-01" );
StartBar = DateTimeConvert(2, start);
EndBar = DateTimeConvert(2, end);
//
// on the end bar we read the value of highest high or lowest low since the start bar
myH = ValueWhen( EndBar, HighestSince( StartBar, High ) );
myL = ValueWhen( EndBar, LowestSince( StartBar, Low ) );
// display price and high / low arrays
Plot( Close, "Close", colorDefault, styleBar|styleThick );
Plot( myH, "myH", colorGreen, styleThick );
Plot( myL, "myL", colorRed, styleThick );
// grey lines show how highest high / lowest low develop since start bar
Plot( HighestSince( StartBar, High ), "", colorgrey50 );
Plot( LowestSince( StartBar, Low ), "", colorgrey50 );
// area chart shows the zone we are reading our values from
Plot( tn >= StartTime AND tn <= Endtime, "",
ColorBlend( colorYellow, colorWhite, 0.9 ),
styleArea | styleOwnScale, 0, 1, 0, -1)
In fact if I want to get the indicator similar as the first post we can remove every thing except latest plot
However, there must be a trick that I'm not doing well, right?
//tn = TimeNum();
// define start/end hours in TimeNum format
//StartTime = 93000;
//Endtime = 113000;
// these conditions are true when TimeNum of the bar equals startime/endtime
//StartBar = tn == StartTime;
//EndBar = tn == Endtime;
// my code
start = ParamDate( "START", "2001-01-01" );
end = ParamDate( "END", "2002-01-01" );
StartBar = DateTimeConvert(2, start);
EndBar = DateTimeConvert(2, end);
//
/*
// on the end bar we read the value of highest high or lowest low since the start bar
myH = ValueWhen( EndBar, HighestSince( StartBar, High ) );
myL = ValueWhen( EndBar, LowestSince( StartBar, Low ) );
// display price and high / low arrays
Plot( Close, "Close", colorDefault, styleBar|styleThick );
Plot( myH, "myH", colorGreen, styleThick );
Plot( myL, "myL", colorRed, styleThick );
// grey lines show how highest high / lowest low develop since start bar
Plot( HighestSince( StartBar, High ), "", colorgrey50 );
Plot( LowestSince( StartBar, Low ), "", colorgrey50 );
*/
Plot( Close, "Close", colorDefault );
// area chart shows the zone we are reading our values from
Plot( tn >= StartBar AND tn <= EndBar, "",
ColorBlend( colorRed, colorWhite, 0.9 ),
styleArea | styleOwnScale, 0, 1, 0, -1);
@Vegeta, probably, the simplest way to do it is to directly use the dates returned from the ParamDate() function invoked with the "format" argument set to 2.
dt = DateTime();
// Check the documentation for ParamDate
startDate = ParamDate( "START", "2021-01-01", 2 );
endDate = ParamDate( "END", "2022-01-01", 2 );
Plot( Close, "Close", colorDefault );
// area chart shows the zone we are reading our values from
Plot( dt >= StartDate AND dt <= EndDate, "",
ColorBlend( colorRed, colorWhite, 0.9 ),
styleArea | styleOwnScale, 0, 1, 0, -1);