I want to create an indicator that represents the value of Close, 3 months ago.
Not 60/70 days ago, but exactly 3 months ago
If today is March 31, I will have to publish the close value at 31 December
I create an indicator that represents in DateNumber format, the Date of 3 months ago,
I now do not know how to compile the array with the Close, which reads in that precise DateNumber the Close value.
I tried with ValueWhen(with ValueWhen, if I position the cursor in the chart, after making the plot, the past value changes. I probably do not use it, recall, how it would be used.)
and also with LookUp but I did not succeed.
The problem is to calculate the market days between today's date and the synthesized date of 3 months ago.
I tried to use the user function found in this link http://www.amibroker.org/userkb/index.php?s=daycount
but it does not work because I'm using it because it gives me a mistake
Anyone kindly can give me some help, guidance on how to overcome this seemingly banal problem, but complicated for me?
As @portfoliobuilder mentioned, pretty often exactly 3 months back means Sunday or Saturday.
But if you wanted just the close at the end of each month, 3 months back, you can get it quite easily
TimeFrameGetPrice( "C", inMonthly, -3 );
But I guess that you are not interested in just monthly close.
Getting close 3 months back on daily (bar by bar) basis is tricky because each bar you need to lookup back different number of bars and if exact match is missing you need to get predecessor. This is quite a bit of work. One of possible solutions look like this:
dt = DateTime();
// get date that is exactly 3 months back
dt3m = DateTimeAdd( dt, -3, inMonthly );
for( i = 0; i < BarCount; i++ )
{
cl3m[ i ] = Lookup( Close, dt3m[ i ], -1 );
}
Plot( Cl3m, "Close 3 months back", colorRed );
Title = "Now = " + DateTimeToStr( SelectedValue( dt ) ) +
" 3 months back = " + DateTimeToStr( SelectedValue( dt3m ) ) +
" Close 3 months back " + cl3m;
Thank you so much!
It’s amazing how @Tomasz, with only one line created the array with the back date of 3 months
It’s even more amazing as with the loop that invokes Lookup has solved
After a year working in AFL I feel very small, but I will grow
Thank you !!