|
Post by bobpit on Apr 1, 2016 10:31:14 GMT
It seems to me that TimeFrameSet compresses the bars differently than if I changed the display interval through the chart combo box.
When I do TimeFrameSet, I get different date/times for the bars, than if I simply had changed the interval from the chart combo box. My database is 1min and I use the following script for testing:
SetChartOptions( 0, chartShowArrows | chartShowDates ); SetBarsRequired(-2,-2); _N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g {{VALUES}}", O, H, L, C ) );
printf("Before TFSet, Interval()= %g, C = %g, time = "+DateTimeToStr(SelectedValue(datetime()))+"\n",Interval(), C); Plot( C, "Close", ParamColor( "Color", colorDefault ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() ); TF=in15Minute; TimeFrameSet( TF ); printf("Inside TFSet, Interval()= %g, C = %g, time = "+DateTimeToStr(SelectedValue(datetime()))+"\n",Interval(), C); TimeFrameRestore();
I set the chart bar interval to 1min.
I get this output when I click the 3rd bar from the end: Before TFSet, Interval()= 60, C = 1.38212, time = 2014-04-16 16:23:00 Inside TFSet, Interval()= 900, C = 1.38332, time = 2014-04-16 15:59:00
I get this output when I click the 2nd bar from the end: Before TFSet, Interval()= 60, C = 1.38217, time = 2014-04-16 16:24:00 Inside TFSet, Interval()= 900, C = 1.38344, time = 2014-04-16 16:14:00
I set the chart bar interval to 15min.
I get this output when I click the 3rd bar from the end: Before TFSet, Interval()= 900, C = 1.38332, time = 2014-04-16 15:45:00 Inside TFSet, Interval()= 900, C = 1.38332, time = 2014-04-16 15:45:00
I get this output when I click the 2nd bar from the end: Before TFSet, Interval()= 900, C = 1.38344, time = 2014-04-16 16:00:00 Inside TFSet, Interval()= 900, C = 1.38344, time = 2014-04-16 16:00:00
You see, when I set the chart interval to 15min, I get nice rounded times (15:45:00, 16:00:00). But when I do it from AFL I the times are shifted by 1min: 15:59:00, 16:14:00.
Am I doing something wrong? Why am I experiencing this?
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on Apr 1, 2016 15:07:07 GMT
You have to use TimeFrameExpand.
Also please use code tags for better readability and in order to avoid formatting issues if inserting code in posts. Thanks!
|
|
|
Post by bobpit on Apr 1, 2016 15:53:23 GMT
ok, here I used Timeframeexpand, like you suggested. I used both expandfirst and expandlast. I still get UNrounded times shifted by 1min : 15:59:00, 16:14:00.
SetChartOptions( 0, chartShowArrows | chartShowDates ); SetBarsRequired(-2,-2); _N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g {{VALUES}}", O, H, L, C ) );
printf("Before TFSet, Interval()= %g, C = %g, time = "+DateTimeToStr(SelectedValue(datetime()))+"\n",Interval(), C); Plot( C, "Close", ParamColor( "Color", colorDefault ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() ); TF=in15Minute; TimeFrameSet( TF ); printf("Inside TFSet, Interval()= %g, C = %g, time = "+DateTimeToStr(SelectedValue(TimeFrameExpand(datetime(),TF)))+"\n",Interval(), TimeFrameExpand(C,TF)); TimeFrameRestore();
I still cannot make the compress/expand commands to behave as if I changed the interval from the combo box.
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on Apr 1, 2016 16:05:59 GMT
This is how it's done in the state of Denmark EnableTextOutput( 0 );
SetChartOptions( 0, chartShowArrows | chartShowDates ); //SetBarsRequired(-2,-2);
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g {{VALUES}}", O, H, L, C ) );
LTFdtstr = DateTimeToStr(SelectedValue(datetime())); printf( "Before TFSet, LTF: " + Interval(2) + ", C = %g, time = " + LTFdtstr + "\n\n", C ); Plot( C, "Close", ParamColor( "Color", colorDefault ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
TF = in15Minute; expandmode = expandFirst; // other modes expandLast and expandPoint, see manual!!
TimeFrameSet( TF ); MTFclose = Close; MTFdt = DateTime(); HTFintstr = Interval(2); // does not require expanding TimeFrameRestore();
MTFclose = TimeFrameExpand( MTFclose, TF, expandmode ); MTFdt = TimeFrameExpand( MTFdt, TF, expandmode ); MTFdtstr = DateTimeToStr( SelectedValue( MTFdt ) );
printf( "After TFSet, HTF: " + HTFintstr + ", C = %g, time = " + MTFdtstr + "\n", MTFclose ); www.amibroker.com/guide/afl/timeframeset.html
|
|
|
Post by bobpit on Apr 1, 2016 17:22:10 GMT
Hello
Thank you very much for the code. It is more modular than mine.
The problem remains:
I want to see high TimeFrame bars with times starting at: 15:45, 16:00, 16:15, etc
What I see is 15:44, 15:59, 16:14 etc.
Here is sample output from your code: Before TFSet, LTF: 1-minute, C = 1.3834, time = 2014-04-16 16:12:00
Inside TFSet, HTF: 15-minute, C = 1.38344, time = 2014-04-16 16:14:00
They are off by 1 minute. Just like my original code.
Could it be an issue with my data? Do you get nice rounded numbers with your data?
As a secondary issue, I prefer to read the high timeframe bars Unexpanded. This is why I had the printf inside the TimeFrameSet/TimeFrameRestore structure.
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on Apr 1, 2016 17:52:21 GMT
Hello Thank you very much for the code. It is more modular than mine. The problem remains: I want to see high TimeFrame bars with times starting at: 15:45, 16:00, 16:15, etc What I see is 15:44, 15:59, 16:14 etc. Here is sample output from your code: Before TFSet, LTF: 1-minute, C = 1.3834, time = 2014-04-16 16:12:00 Inside TFSet, HTF: 15-minute, C = 1.38344, time = 2014-04-16 16:14:00 They are off by 1 minute. Just like my original code. Could it be an issue with my data? Do you get nice rounded numbers with your data? Not it's not possible within used TF functions, AFAIK. Well, you could add rest of interval yourself. As a secondary issue, I prefer to read the high timeframe bars Unexpanded. This is why I had the printf inside the TimeFrameSet/TimeFrameRestore structure. But then it is not aligned to the lower TF (because of HTF being in compressed mode within timeframeset).
|
|
|
Post by bobpit on Apr 1, 2016 18:14:16 GMT
I do not want to align Lower and Upper TimeFrame. Maybe I have not communicated correctly what my issue is exactly. Please allow me to ask again:
Both my code and your code seem to compress the upper timeframe to values like: 15:44, 15:59, 16:14 etc.
What I want is to get values like : 15:45, 16:00, 16:15, etc
Why can't I get this?
When you test your code with your data, what values do you get?
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on Apr 1, 2016 18:23:16 GMT
I get the same ones as you.
If you expand DT then you may uses DateTimeAdd() function to output the way you want. The addition value would be Interval() of LTF.
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on Apr 1, 2016 18:34:21 GMT
If you expand DT then you may uses DateTimeAdd() function to output the way you want. The addition value would be Interval() of LTF. Here is what I mean And additionally printf within TimeFrameSet EnableTextOutput( 0 );
SetChartOptions( 0, chartShowArrows | chartShowDates ); //SetBarsRequired(-2,-2);
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g {{VALUES}}", O, H, L, C ) );
LTFdtstr = DateTimeToStr(SelectedValue(datetime())); printf( "Before TFSet, LTF: " + Interval(2) + ", C = %g, time = " + LTFdtstr + "\n\n", C ); Plot( C, "Close", ParamColor( "Color", colorDefault ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
TF = in15Minute; expandmode = expandFirst; // other modes expandLast and expandPoint, see manual!!
LTFint = Interval(); // for datetimeadd(), keep it outside of timeframeset
TimeFrameSet( TF ); MTFclose = Close; MTFdt = DateTime(); HTFintstr = Interval(2); // does not require expanding
if( SelectedValue( MTFdt ) == LastValue( MTFdt ) ) MTFdtstr = DateTimeToStr( LastValue( MTFdt ) ); else MTFdtstr = DateTimeToStr( Datetimeadd( SelectedValue( MTFdt ), 1, LTFint ) ); printf( "Inside TFSet, HTF: " + HTFintstr + ", C = %g, time = " + MTFdtstr + "\n\n", MTFclose ); TimeFrameRestore();
MTFclose = TimeFrameExpand( MTFclose, TF, expandmode );
MTFdt = TimeFrameExpand( MTFdt, TF, expandmode ); if( SelectedValue( MTFdt ) == LastValue( MTFdt ) ) MTFdtstr = DateTimeToStr( LastValue( MTFdt ) ); else MTFdtstr = DateTimeToStr( Datetimeadd( SelectedValue( MTFdt ), 1, LTFint ) );
printf( "After TFSet, HTF: " + HTFintstr + ", C = %g, time = " + MTFdtstr + "\n", MTFclose );
|
|
|
Post by bobpit on Apr 1, 2016 18:46:53 GMT
I get the same ones as you. ok, then I am not crazy. Would you have any idea why this is happening? When I use the chart combo box to select 15min, I get nice round numbers: 15:45, 16:00, 16:15 etc. Why can't I get the same through AFL? If you expand DT then you may uses DateTimeAdd() function to output the way you want. The addition value would be Interval() of LTF. No point doing this. I need 15min bars through AFL. I want to know that the OHLC values correspond to the correct start and end times of the bars.
|
|