Daily range
Posted: Tue Feb 24, 2009 5:25 am
Hi,
Friends from the TS forum and myself have created a Daily range indicator which check the range of yesterday, the average range of the last 7 days and the range of today.
The use of this indicator is for day traders. most of the stocks "run" every day the same range as their average range.
It will be great if TRO or other forum member will create a slot machine for RS from this indicator.
We can milk these cows also.
Here is the code:
The function
Friends from the TS forum and myself have created a Daily range indicator which check the range of yesterday, the average range of the last 7 days and the range of today.
The use of this indicator is for day traders. most of the stocks "run" every day the same range as their average range.
It will be great if TRO or other forum member will create a slot machine for RS from this indicator.
We can milk these cows also.
Here is the code:
Code: Select all
[SameTickOpt=True];
// Noam Daily Hi-Lo
// by FiveV updated 21 Feb. 2009
// Re: 86074
// Data1 must be intraday -- Data2 not required
Inputs:
AvgLength(7), // length to determine Daily Range Average
Decimal(2), // How many decimals you want displayed in text
Placement(2), // 1 = Upper Left corner, 2 = Upper Right, 3 = Lower Right, 4 = Lower left
Avg_Color(rgb(255,255,0)), // You pick the color for the Average Text
Yrange_Color(rgb(17,217,175)), // Yesterday's Range color
Trange_Color(rgb(255,128,30)), // Today's Range color
Percent(3), // If screen height = 100% then this is how far off top or bottom you want to display corner text
SpreadFactor(2), // A factor to help scale corner text so they don't display over each other
Printline(true), // Print H / L lines or not
PrintHiLoText(true), // Print H / L text or not
MinToRight(10), // How far to the right you want H / L text to display
LineSize(0), // The size line you want printed: 0 to 6
LineStyle(Tool_Dotted), // pick your favorite line style
YesterdayColor(RGB(255,255,255)), // Yesterday's H / L text color
TodayColor(RGB(255,255,0)); // Today's H / L text color
Variables:
AvgValue(0),
YH(0),
YL(0),
TH(0),
TL(0),
Hsum(0),
Lsum(0),
Yrange(0),
Trange(0),
TotalRange(0),
PlacementHolder(0),
Text_ID1(-1),
Text_ID2(-1),
Text_ID3(-1),
StartPoint(0),
EndPoint(0),
sdate(0),
edate(0),
YHL(0),
YLL(0),
THL(0),
TLL(0),
TxtYH(0),
TxtYL(0),
TxtTH(0),
TxtTL(0),
TxtYR(0),
TxtTR(0),
TxtAvg(0),
Decp(0),
LastBar(False);
If BarStatus(1) = 2 Then
Begin
YH = HighD(1);
YL = LowD(1);
TH = HighD(0);
TL = LowD(0);
// this section to calculate the Average without requiring Daily Symbol as Data2
TotalRange = 0;
For Value1 = 0 To AvgLength - 1
Begin
TotalRange = TotalRange + (HighD(Value1) - LowD(Value1));
End;
If AvgLength <> 0 Then AvgValue = TotalRange / AvgLength;
Trange = TH - TL;
Yrange = YH - YL;
PlacementHolder = Placement;
StartPoint = SessionStartTime(0, 1);
EndPoint = Time;
sdate = IFF(Time < SessionStartTime(0, 1), CalcDate(Date, -1), Date);
edate = Date;
DecP = StrLen(NumToStr(PriceScale, 0)) - 1;
LastBar = LastBarOnChart;
End; //BarStatus
Once If CurrentBar = 1 Then
Begin
If Text_ID1 = -1 Then Text_ID1 = Text_New(Date, Time, 0, " ");
If Text_ID2 = -1 Then Text_ID2 = Text_New(Date, Time, 0, " ");
If Text_ID3 = -1 Then Text_ID3 = Text_New(Date, Time, 0, " ");
End;
Text_SetString(Text_ID1, NumToStr(Avgvalue, decimal) + ": Avg : " + NumToStr(AvgLength, 0) + " days ");
Value1 = TextLocale(Text_ID1, placementholder, Avg_Color, percent);
Text_SetString(Text_ID2, NumToStr(Yrange, decimal) + ": Y Range ");
Value1 = TextLocale(Text_ID2, placementholder, Yrange_Color, percent * spreadfactor * 1);
Text_SetString(Text_ID3, NumToStr(Trange, decimal) + ": T Range ");
Value1 = TextLocale(Text_ID3, placementholder, Trange_Color, percent * spreadfactor * 1.5);
// this section changed for "speed" . . less processor time to create only four trendlines
// at the beginning bar and then update them rather than delete old and redraw.
If Barnumber = 1 Then
Begin
TxtYH = Text_New(Date, Time, Close, " ~ " + NumToStr(YH, Decp) + ": YH");
Text_SetColor(TxtYH, YesterdayColor);
Text_SetStyle(TxtYH, 0, 2);
TxtYL = Text_New(Date, Time, Close, " ~ " + NumToStr(YL, Decp) + ": YL");
Text_SetColor(TxtYL, YesterdayColor);
Text_SetStyle(TxtYL, 0, 2);
TxtTH = Text_New(Date, Time, Close, " ~ " + NumToStr(TH, Decp) + ": TH");
Text_SetColor(TxtTH, TodayColor);
Text_SetStyle(TxtTH, 0, 2);
TxtTL = Text_New(Date, Time, Close, " ~ " + NumToStr(TL, Decp) + ": TL");
Text_SetColor(TxtTL, TodayColor);
Text_SetStyle(TxtTL, 0, 2);
End Else
Begin
If PrintLine And LastBar Then
Begin
YHL = TL_New(sdate, StartPoint, YH, edate, Time, YH);
YLL = TL_New(sdate, StartPoint, YL, edate, Time, YL);
THL = TL_New(sdate, StartPoint, TH, edate, Time, TH);
TLL = TL_New(sdate, StartPoint, TL, edate, Time, TL);
TL_SetBegin(YHL, sdate, StartPoint, YH);
TL_SetEnd(YHL, sdate, Time, YH);
TL_SetExtLeft(YHL, False);
TL_SetExtRight(YHL, False);
TL_SetStyle(YHL, LineStyle);
TL_SetColor(YHL, YesterdayColor);
TL_SetSize(YHL, LineSize);
// ----------------
TL_SetBegin(YLL, sdate, StartPoint, YL);
TL_SetEnd(YLL, sdate, Time, YL);
TL_SetExtLeft(YLL, False);
TL_SetExtRight(YLL, False);
TL_SetStyle(YLL, LineStyle);
TL_SetColor(YLL, YesterdayColor);
TL_SetSize(YLL, LineSize);
// ----------------
TL_SetBegin(THL, sdate, StartPoint, TH);
TL_SetEnd(THL, sdate, Time, TH);
TL_SetExtLeft(THL, False);
TL_SetExtRight(THL, False);
TL_SetStyle(THL, LineStyle);
TL_SetColor(THL, TodayColor);
TL_SetSize(THL, LineSize);
// ----------------
TL_SetBegin(TLL, sdate, StartPoint, TL);
TL_SetEnd(TLL, sdate, Time, TL);
TL_SetExtLeft(TLL, False);
TL_SetExtRight(TLL, False);
TL_SetStyle(TLL, LineStyle);
TL_SetColor(TLL, TodayColor);
TL_SetSize(TLL, LineSize);
End;
If PrintHILOtext Then
Begin
Text_SetString(TxtYH, " ~ " + NumToStr(YH, Decp) + ": YH");
Text_SetLocation(TxtYH, CalcDate(Date, 0), CalcTime(Time, MinToRight), YH);
Text_SetColor(TxtYH, YesterdayColor);
Text_SetStyle(TxtYH, 0, 2);
// ----------------
Text_SetString(TxtYL, " ~ " + NumToStr(YL, Decp) + ": YL");
Text_SetLocation(TxtYL, CalcDate(Date, 0), CalcTime(Time, MinToRight), YL);
Text_SetColor(TxtYL, YesterdayColor);
Text_SetStyle(TxtYL, 0, 2);
// ----------------
Text_SetString(TxtTH, " ~ " + NumToStr(TH, Decp) + ": TH");
Text_SetLocation(TxtTH, CalcDate(Date, 0), CalcTime(Time, MinToRight), TH);
Text_SetColor(TxtTH, TodayColor);
Text_SetStyle(TxtTH, 0, 2);
// ----------------
Text_SetString(TxtTL, " ~ " + NumToStr(TL, Decp) + ": TL");
Text_SetLocation(TxtTL, CalcDate(Date, 0), CalcTime(Time, MinToRight), TL);
Text_SetColor(TxtTL, TodayColor);
Text_SetStyle(TxtTL, 0, 2);
End; //printHILOtext
End; // Barnumber
The function
Code: Select all
[SameTickOpt=True];
{See Textplay Indicator for explanation of this}
{
June 2008 Mindset from original code by DIDA.
See adjoining indicator textplay or Textplay3 for this functions use as an example.
Allows you to place a piece of Text (TextID) using
Text_SetString (TextID,"Mytext")
at any of the 4 corners of the visible chart.
Call = TextLocale(TextID,Placement,TextColor,Pcnt);
}
Inputs:
TextID(NumericSimple),
Placement(NumericSimple), {Clockface with left hand upper corner being 1, 2, 3 and 4}
TextColor(NumericSimple),
Pcnt(NumericSimple); {Start at 0 then increment by Offset ( see varibale) }
Variables:
ValidTextID(False),
Left_ID(0),
Right_ID(0),
High_ID(0),
Low_ID(0),
Offset(0);
If LastBarOnChart And BarStatus(1) = 2 Then Begin
Left_ID = GetAppInfo(aiLeftDispDateTime);
Right_ID = GetAppInfo(aiRightDispDateTime);
High_ID = GetAppInfo(aiHighestDispValue);
Low_ID = GetAppInfo(aiLowestDispValue);
Offset = ((High_ID - Low_ID) * .01); { 1% of chart height. Then Pcnt (Input) becomes Percent height of chart}
ValidTextID = Text_Exist(TextID);
If ValidTextID Then Begin
If Placement = 4 {South West} Then Begin
Text_SetLocation(textid, JulianToDate(IntPortion(Left_ID)), MinutesToTime(FracPortion(Left_ID) * 60 * 24), Low_ID + (pcnt * offset));
Text_SetStyle(TextID, 0, 1);
End;
If Placement = 3 {South East} Then Begin
Text_SetLocation(textid, JulianToDate(IntPortion(Right_ID)), MinutesToTime(FracPortion(Right_ID) * 60 * 24), Low_ID + (Offset * pcnt));
Text_SetStyle(TextID, 1, 1);
End;
If Placement = 2 {North East} Then Begin
Text_SetLocation(textid, JulianToDate(IntPortion(Right_ID)), MinutesToTime(FracPortion(Right_ID) * 60 * 24), High_ID - (Offset * pcnt));
Text_SetStyle(TextID, 1, 0);
End;
If Placement = 1 {North West} Then Begin
Text_SetLocation(textid, JulianToDate(IntPortion(Left_ID)), MinutesToTime(FracPortion(Left_ID) * 60 * 24), High_ID - (Offset * pcnt));
Text_SetStyle(TextID, 0, 0);
End;
Text_SetColor(TextID, TextColor);
End Else
RaiseRunTimeError("TextID does not exist.");
End;
TextLocale = 1 ;