Ravi.V
March 14, 2025, 9:56am
1
Hi Community,
Greetings to all!
I am working on a use case where I want to plot the day high and day low values for a specific date, in which DATE is I intend to supply as a parameter. Despite my efforts and the knowledge I have, I haven’t been able to achieve this successfully.
Here is the code I attempted to write (please note that it may not be error-free):
_SECTION_BEGIN("Special Levels");
ADate = ParamDate("Select ADate","DD-MM-YY", 1);
ADayLow = TimeFrameGetPrice("L", inDaily, 13022025);
ADayHigh = TimeFrameGetPrice("High", inDaily, -ADate);
GfxTextOut("ADayLow:" + ADayLow , 10, 250);
GfxTextOut("ADayHigh:" + ADayHigh , 10, 280);
AD = DateTimeConvert( 0, StrToNum(ADate), time = Null );
ADayH = ValueWhen(AD == DateNum(), H);
ADayL = ValueWhen(AD == DateNum(), L);
Plot(ADayL, "ADay Low", colorgreen, styleDots) ;
Plot(ADayH, "ADay High", colorOrange, styleDots) ;
GfxTextOut("AD:" + AD, 10, 350);
_SECTION_END( );
If anyone could provide guidance or suggest improvements, I would greatly appreciate it!
Thank you in advance for your help!
nsm51
March 14, 2025, 10:23am
2
Both these lines have wrong 3rd argument.
Don't pass the date,
Calculate how far back in days the date is and pass the scalar value.
It is shift like Ref()
beppe
March 14, 2025, 10:47am
3
@Ravi.V the easiest way to find a single value using a specific user supplied date as a parameter is:
Lookup() function.
The are many examples of usage in the Forum.
Ravi.V
March 14, 2025, 11:14am
4
@beppe I have tried as per your advice.
As you can see from the image, Date is selected as March 11, 2025. Which means, High and Low of the 11th March has to be plotted.
But, seems it's a wrong plotting..!
`_SECTION_BEGIN("Special Levels");
Plot(C, "", colorDefault, styleCandle);
ADate = ParamDate("Select ADate","DD-MM-YY", 1);
ADayLow = Lookup( Low, _DT( ADate ), -1 );
ADayHigh = Lookup( High, _DT( ADate ), -1 );
GfxTextOut("ADayLow:" + ADayLow, 10, 50);
GfxTextOut("ADayHigh:" + ADayHigh, 10, 80);
Plot(ADayLow, "ADay Low", colorWhite, styleDots) ;
Plot(ADayHigh, "ADay High", colorWhite, styleDots) ;
_SECTION_END( );
`
beppe
March 14, 2025, 11:29am
5
@ravi be sure to enter in the parameter field the date in your Windows default format.
I tested your code (in Daily timeframe - I did not look attentively at the chart you posted - sorry) adding 2 lines and it works as expected:
GfxTextOut("ADate:" + DateTimeToStr(_DT(aDate)), 10, 110);
_N(Title = StrFormat("{{NAME}} - " +FullName() +
" - {{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 )) ));
If you work in a lower timeframe you should use the method suggested by @nms .
nsm51
March 14, 2025, 11:31am
6
@beppe
Shouldn't we rather go with calculate the day offset
and use TimeFrameGetPrice() daily H/L?
because chart TF is lower and OP wants Daily H/L of a previous date
1 Like
beppe
March 14, 2025, 2:19pm
7
@Ravi.V , as an alternative method you can also use SparseCompress() (may not be the best way, but in your case it seems to work well enough):
Plot( C, "", colorDefault, styleCandle );
dt = DateTime();
aDatenum = ParamDate( "Select ADate", "DD-MM-YY", 0 );
aDateStr = DateTimeToStr(DateTimeConvert(2, aDatenum));
SetOption("WarningLevel", 3);
dn = Datenum();
firstBar = dn != ref( dn, -1 ); // used to better visualize the bars in a day ranges
condition = dn == aDatenum;
bars = SparseCompress( condition, H );
date_H = LastValue( Highest( bars ) );
bars = SparseCompress( condition, L );
date_L = LastValue( Lowest( bars ) );
if (date_H > 0) // ignore invalid dates
{
// comment out if not needed
Plot( iif( firstBar, 1, null ), "", colorRGB(129, 126, 129), styleArea | styleOwnScale | StylenoTitle | styleNoLabel , 0, 1 );
Plot( date_H, StrFormat("H of %s", aDateStr), colorOrange, styleLine | styleThick );
Plot( date_L, StrFormat("L of %s", aDateStr), colorPaleGreen, styleLine | styleThick );
}
// GfxTextOut("Selected Date:" + aDateStr, 0, 24);
_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 ) ) ) );
3 Likes
Ravi.V
March 14, 2025, 2:50pm
8
@beppe I just wanted to express my heartfelt gratitude for your assistance. I truly appreciated your support
@nsm51 Thank you..!!