Trying to use different time frame based condition in code

For an example I am trying to compare if today's close is greater than daily MA of last 20 days along with the condition if this week's close is also greater than weekly MA of last 10 days.

So, I am first trying to check if I am getting correct weekly close when I run explore with daily periodicity using below codes:

TimeFrameSet(inWeekly);
WC=Close;
TimeFrameRestore()

or

WC=TimeFrameExpand(C,inWeekly);

but none of them is returning correct weekly close price of the instrument.

Can someone please suggest ways to achieve above requirement

Read this AFL Function Reference - TIMEFRAMESET

TimeFrameSet(inWeekly);
wc=Close;
TimeFrameRestore();

AddColumn(TimeFrameExpand(wc,inWeekly),"Weekly_Close");

There is much easier and quicker method to get weekly close

http://www.amibroker.com/guide/afl/timeframegetprice.html

1 Like

Thank you very much for the answer. I am able to use this code, but when I use the given code it takes Friday as the start of the week and Thursday as the end of the week. Do I need to change anything on the Amibroker options to resolve that?

Also, if in my code I am trying to use the same logic for a bit complex calculation like Super Trend, it's not working. So, if you can guide me how to find weekly parameters like in case of SuperTrend TrendUp, TrendDown and trend.

Thank you very much Tomasz. TimeFrameGetPrice function perfectly helps me to find OHLC data based on week time frame. But if I want to find a bit more complex value like SuperTrend variables, then could you please guide me how to achieve that?