Inputs:
StartTime(800), // Start time of session
EndTime(900), // End time of openingsrange
ExtendOpeningsRange(False), // Extending the openings range
TextOffSet(1), // The distance between the text and the lines, in points of the pricescale
TextAlignment(2), // Alignment of the text object: 0: to right of bar, 1: to left of bar, 2: centered on bar
FontSize(9), // Font size of the text objects
FontName("Verdana"), // Font type of the text objects
High_Color(RGB(0, 255, 0)), // Color for the high line and text
Mid_Color(RGB(255, 128, 0)), // Color for the mid line and text
Low_Color(RGB(255, 0, 0)), // Color for the low line and text
High_Line_Tickness(2), // Tickness of the high line
Mid_Line_Tickness(1), // Tickness of the middle line
Low_Line_Tickness(2), // Tickness of the low line
High_Line_Style(2), // Style of the high line
Mid_Line_Style(3), // Style of the mid line
Low_Line_Style(2) // Style of the low line
;
Variables:
sessionStart(SessionStartTime(0, 1)), opRangeHigh(0), opRangeLow(999999), barsSinceStart(0), alreadyPlotted(False),
numOfDecimals(Round(Log(PriceScale) / Log(10), 0)), offset(TextOffSet * (MinMove / PriceScale)), lineOffset(0),
tlHigh(0), tlLow(0), tlMid(0), opRangeActive(False),
sessionEnd(SessionEndTime(0, SessionCount(0)) * 100), beginTime(StartTime * 100), endingTime(EndTime * 100);
// Reset previous values
if (Date <> Date[1]) then begin
opRangeHigh = 0;
opRangeLow = 999999;
barsSinceStart = 0;
alreadyPlotted = False;
opRangeActive = True;
end;
// Collect openingsbar range
if (Time_s >= beginTime) and (Time_s <= endingTime) then begin
opRangeHigh = MaxList(High, opRangeHigh);
opRangeLow = MinList(Low, opRangeLow);
barsSinceStart = barsSinceStart + 1;
end;
// Start plotting
if (Time_s >= endingTime) and (alreadyPlotted = False) then begin
// Save values for the trendlines (needed for extending later on)
tlHigh = opRangeHigh;
tlMid = (opRangeHigh + opRangeLow) * 0.50;
tlLow = opRangeLow;
// Plot the text
value20 = IFF(barsSinceStart > 1, barsSinceStart - 1, barsSinceStart);
value1 = Text_New_s(Date, Time_s[value20 * 0.50], tlHigh + offset, Text("High = ", NumToStr(tlHigh, numOfDecimals)));
value2 = Text_New_s(Date, Time_s[value20 * 0.50], tlLow - (offset * 2), Text("Midpoint = ", NumToStr(tlMid, numOfDecimals)));
value3 = Text_New_s(Date, Time_s[value20 * 0.50], tlLow - offset, Text("Low = ", NumToStr(tlLow, numOfDecimals)));
// Change colour of text instrument
Text_SetColor(value1, High_Color);
Text_SetColor(value2, Mid_Color);
Text_SetColor(value3, Low_Color);
// Change the alignment of the text object
Text_SetStyle(value1, TextAlignment, 2);
Text_SetStyle(value2, TextAlignment, 2);
Text_SetStyle(value3, TextAlignment, 2);
// Change the font size
Text_SetSize(value1, FontSize);
Text_SetSize(value2, FontSize);
Text_SetSize(value3, FontSize);
// Change the font type
Text_SetFontName(value1, FontName);
Text_SetFontName(value2, FontName);
Text_SetFontName(value3, FontName);
// Draw the trendlines
value10 = TL_New_s(Date, Time_s[value20], tlHigh, Date, Time_s, tlHigh);
value11 = TL_New_s(Date, Time_s[value20], tlMid, Date, Time_s, tlMid);
value12 = TL_New_s(Date, Time_s[value20], tlLow, Date, Time_s, tlLow);
// Change colour of the lines
TL_SetColor(value10, High_Color);
Tl_SetColor(value11, Mid_Color);
TL_SetColor(value12, Low_Color);
// Change the style of the lines
TL_SetStyle(value10, High_Line_Style);
TL_SetStyle(value11, Mid_Line_Style);
TL_SetStyle(value12, Low_Line_Style);
// Change the width of the lines
TL_SetSize(value10, High_Line_Tickness);
TL_SetSize(value11, Mid_Line_Tickness);
TL_SetSize(value12, Low_Line_Tickness);
alreadyPlotted = True;
end;
if (ExtendOpeningsRange = True) and (opRangeActive = True) and (Time_s < sessionEnd) and (Time_s > endingTime) then begin
// Check if the openings range is still valid
if (Close > tlHigh) or (Close < tlLow) then
opRangeActive = False;
// Only extend lines as long as the openings range isn't violated
if (opRangeActive = True) then begin
value20 = TL_SetEnd_s(value10, Date, Time_s, tlHigh);
value21 = TL_SetEnd_s(value11, Date, Time_s, (tlHigh + tlLow) * 0.50);
value22 = TL_SetEnd_s(value12, Date, Time_s, tlLow);
end;
end; //: ExtendOpeningsRange
|