Code: Select all
inputs: PeriodStartTime( 0930 ),
PeriodEndTime( 1600 ),
Transparency_0_100( 20) ;
vars: double SessionHigh( 0 ),
double SessionLow( 0 ),
intrabarpersist double PriorSessionHigh( 0 ),
intrabarpersist double PriorSessionLow( 0 ),
intrabarpersist bool FirstTick( false ),
OkToDraw( true ),
DateTime SessionStartBar( NULL ),
DTPoint TextDTPoint( NULL ),
Rectangle MyRectangle( NULL ),
TextLabel MyTextLabel( NULL ),
int FillTrans( Transparency_0_100 * 2.55 ),
DayofWeekString("") ;
method void DrawRectangle( )
variables: DTPoint MyStartDT, DTPoint MyEndDT ;
begin
MyStartDT = DTPoint.Create( SessionStartBar, SessionLow ) ;
MyEndDT = DTPoint.Create( BarDateTime, SessionHigh ) ;
MyRectangle = Rectangle.Create( MyStartDT, MyEndDT ) ; { create the rectangle }
MyRectangle.Persist = true ;
MyRectangle.FillColor = Color.FromArgb( FillTrans, 128,128,128 ) ;
//MyRectangle.Color = Color.Yellow ;
MyRectangle.Color = Color.FromArgb( FillTrans, 255,255,255 ) ;
DrawingObjects.Add( MyRectangle ) ;
end ;
method void UpdateRectangle ()
variables: DTPoint MyStartDT, DTPoint MyEndDT ;
begin
MyStartDT = DTPoint.Create( SessionStartBar, SessionLow ) ;
MyEndDT = DTPoint.Create( BarDateTime, SessionHigh ) ;
MyRectangle.SetEndPoint( MyEndDT ) ;
MyRectangle.SetStartPoint( MyStartDT ) ;
end ;
method void CreateText()
begin
if Dayofweek(Date) = 1 then DayofWeekString = "Mon"
else if Dayofweek(Date) = 2 then DayofWeekString = "Tue"
else if Dayofweek(Date) = 3 then DayofWeekString = "Wed"
else if Dayofweek(Date) = 4 then DayofWeekString = "Thu"
else if Dayofweek(Date) = 5 then DayofWeekString = "Fri"
else DayofWeekString = "error";
TextDTPoint = MyRectangle.EndPoint astype DTPoint ;
MyTextLabel = TextLabel.Create( TextDTPoint, DayofWeekString ) ;
MyTextLabel.Color = Color.Aquamarine;
MyTextLabel.Persist = false ;
MyTextLabel.HStyle = HorizontalStyle.right ;
MyTextLabel.VStyle = VerticalStyle.Bottom;
DrawingObjects.Add( MyTextLabel ) ;
end ;
method void UpdateText()
begin
if Dayofweek(Date) = 1 then DayofWeekString = "Mon"
else if Dayofweek(Date) = 2 then DayofWeekString = "Tue"
else if Dayofweek(Date) = 3 then DayofWeekString = "Wed"
else if Dayofweek(Date) = 4 then DayofWeekString = "Thu"
else if Dayofweek(Date) = 5 then DayofWeekString = "Fri"
else DayofWeekString = "error";
TextDTPoint = MyRectangle.EndPoint astype DTPoint ;
MyTextLabel.TextString = DayofWeekString ;
MyTextLabel.PointValue = TextDTPoint ;
end ;
if Time[1] < PeriodStartTime and Time >= PeriodStartTime then
begin
SessionHigh = High ;
SessionLow = Low ;
SessionStartBar = BarDateTime ;
if OkToDraw then
begin
DrawRectangle( ) ;
CreateText() ;
end ;
OkToDraw = false ;
end
else if (( PeriodStartTime < PeriodEndTime ) and ( Time > PeriodStartTime and Time <= PeriodEndTime ) ) or
(( PeriodStartTime > PeriodEndTime ) and ( Time > PeriodStartTime or Time <= PeriodEndTime ))
then
begin
SessionHigh = MaxList( High, SessionHigh ) ;
SessionLow = MinList( Low, SessionLow ) ;
OkToDraw = true ;
end ;
if MyRectangle <> NULL and ((( PeriodStartTime < PeriodEndTime ) and ( Time > PeriodStartTime and Time <= PeriodEndTime ) ) or
(( PeriodStartTime > PeriodEndTime ) and ( Time > PeriodStartTime or Time <= PeriodEndTime ))) then
begin
if PriorSessionHigh <> SessionHigh or
PriorSessionLow = SessionLow or
FirstTick then
begin
UpdateRectangle() ;
UpdateText() ;
end ;
end ;
PriorSessionHigh = SessionHigh ;
PriorSessionLow = SessionLow ;
FirstTick = BarStatus( 1 ) = 2 ;