NexusFi: Find Your Edge


Home Menu

 





How to handle two time frame AFL?


Discussion in Platforms and Indicators

Updated
    1. trending_up 5,031 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

How to handle two time frame AFL?

  #1 (permalink)
Rainman
Israel
 
Posts: 3 since Aug 2013
Thanks Given: 1
Thanks Received: 0

Hi All,
I'm trying to use TimeFrameCompress & TimeFrameExpand in my AFL.
I looked on couple of examples in AB support zone and code exmaples and from some reason i cannot make this work.

1. I've loaded Tick by Tick Data to AB database and set my basic working time frame to 1Min bars.
2. I want to calc AvgDailyVolume and DailyHHV/LLV using TimeFrameCompress and in my logic to get the last value from each one of them during each 1 min bar closes.

The code looks like -
DVC = TimeFrameCompress(Volume, inDaily);
DailyVolumeAvg = MA(DVC, 30); //calculate on daily time frame

//calculate on basic 1 min time frame
dailyAvgVolume = TimeFrameExpand(DailyVolumeAvg ,inDaily);
Plot( dailyAvgVolume , "dailyAvgVolume", colorYellow, styleOwnScale);

The problem is when i'm examing dailyAvgVolume on the chart with 1Min timeframe i see different results of then in daily timeframe. and the correct value is indeed when setting the chart to daily timeframe.

any idea's what's is wrong with this code?

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Exit Strategy
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
Better Renko Gaps
The Elite Circle
Increase in trading performance by 75%
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
34 thanks
Tao te Trade: way of the WLD
24 thanks
GFIs1 1 DAX trade per day journal
15 thanks
Vinny E-Mini & Algobox Review TRADE ROOM
13 thanks
My NQ Trading Journal
11 thanks
  #2 (permalink)
 prouser 
Zurich/Switzerland
 
Posts: 79 since Oct 2014

It outputs wrong result because it contains incorrect code. You haven't read the entire article of the AmiBroker help file. Since it is Volume array you have to use compressVolume. compressLast is default one if nothing is specified.

 
Code
period = 30;
intradaybars = 1440;
timeframe = inDaily;
expandmode = expandFirst;

SetBarsRequired( period*intradaybars, period*intradaybars );

DVC = TimeFrameCompress(Volume, timeframe, compressVolume);
DailyVolumeAvg = MA(DVC, period); //calculate on daily time frame

//calculate on basic 1 min time frame
dailyAvgVolume = TimeFrameExpand(DailyVolumeAvg, timeframe, expandmode);

Plot( dailyAvgVolume, "dailyAvgVolume", colorYellow, styleOwnScale);

Reply With Quote
  #3 (permalink)
Rainman
Israel
 
Posts: 3 since Aug 2013
Thanks Given: 1
Thanks Received: 0


Hi Prouser,
Your reply was very informative and helped me to get some progress.
I've read the entire article but my assumption that 'compressVolume' mode will sum up my volumes and since i needed to calc MA i just got confused and decided to use the default.

I've tried your approach and i still not able so see using Plot() the same values for AvgVol & HHV & LLV when i switch the chart between 1MinBars and DailyBars.

Here is my code -

timeframe = inDaily;
expandmode = expandLast;

DVC = TimeFrameCompress(Volume, timeframe, compressVolume);
DHC = TimeFrameCompress(High, timeframe, compressHigh);
DLC = TimeFrameCompress(Low, timeframe, compressLow);

DAvgVol = TimeFrameExpand(MA(DVC, 30), timeframe, expandmode);
DHHV = TimeFrameExpand(HHV(DHC, 10), timeframe, expandmode);
DLLV = TimeFrameExpand(LLV(DLC, 10), timeframe, expandmode);

as you can see i'm using expandLast and not expandFirst you used in your answer. i changed it because when working with expandFirst i saw specific area's i should get a signal but the system did not found it as such. and i switched to expandLast i got the expected signal.
Having said that, i'd appreciate if you can exaplain the difference between those two modes.

Thanks.

Reply With Quote
  #4 (permalink)
 prouser 
Zurich/Switzerland
 
Posts: 79 since Oct 2014

If I'm using the code of second post I'm getting the same values in 1min compared to setting to daily TF. Not sure what you are doing or seeing.

 
Code
period = 30;
intradaybars = 1440;
timeframe = inDaily;
expandmode = expandFirst;

SetBarsRequired( period*intradaybars, period*intradaybars );

DVC = TimeFrameCompress(Volume, timeframe, compressVolume);
DailyVolumeAvg = MA(DVC, period); //calculate on daily time frame

//calculate on basic 1 min time frame
dailyAvgVolume = TimeFrameExpand(DailyVolumeAvg, timeframe, expandmode);

Plot( dailyAvgVolume, "dailyAvgVolume", colorYellow, styleOwnScale);

dd = Day();

Filter = dd != Ref( dd, -1 ) AND NOT IsNull( dailyAvgVolume);

AddSummaryRows( 63, 1, 4 );
AddTextColumn( Interval(2), "Interval", 1 );
AddColumn( dailyAvgvolume, "DailyAvgVol", 1.0 );
Do you agree that both result lists are showing the same results or are we seeing different things?

1min TF


Daily TF




Difference between expanding modes is explained in the help. AFL Function Reference - TIMEFRAMEEXPAND

Basically expandFirst gives the same results as expandLast if using Ref with one bar delay more compared to expandLast (i.e. expandFirst 1 bar delay and expandLast zero delay).

 
Code
period = 30;
intradaybars = 1440;
timeframe = inDaily;
expandmode = expandFirst;
delay = 0;

SetBarsRequired( period*intradaybars, period*intradaybars );

TimeFrameSet( timeframe );
DVC = Ref( MA( V, period ), -delay );
DHC = Ref( HHV( H, 10 ), -delay );
DLC = Ref( LLV( L, 10 ), -delay );
TimeFrameRestore();

DAvgVol = TimeFrameExpand( DVC, timeframe, expandmode );
DHHV = TimeFrameExpand( DHC, timeframe, expandmode );
DLLV = TimeFrameExpand( DLC, timeframe, expandmode );

Plot( DAvgVol, "dailyAvgVolume", colorYellow, styleOwnScale);
Plot( DHHV , "dailyL", colorGreen, styleLine);
Plot( DLLV, "dailyL", colorRed, styleLine);

dd = Day();

Filter = dd != Ref( dd, -1 );

AddSummaryRows( 63, 1.2 );
AddTextColumn( Interval(2), "Interval", 1 );
AddColumn( DAvgVol, "DailyAvgVol", 1.0 );
AddColumn( DHHV, "DailyHHV", 1.2 );
AddColumn( DLLV, "DailyLLV", 1.2 );
Same here. Same results if using expandfirst and zero delay.










As for your signals. I don't know your entire code so can't know what you are doing wrong there.

Reply With Quote
  #5 (permalink)
Rainman
Israel
 
Posts: 3 since Aug 2013
Thanks Given: 1
Thanks Received: 0

I'll learn your code and implemented it and using the AddColumn will verify i indeed seeing the same results.
Thank you for the detailed reply.

Reply With Quote
  #6 (permalink)
haraj
NGP MS India
 
Posts: 16 since May 2015
Thanks Given: 26
Thanks Received: 2


Rainman View Post
I'll learn your code and implemented it and using the AddColumn will verify i indeed seeing the same results.
Thank you for the detailed reply.

any success? i tried but could not get the desired results.

Reply With Quote




Last Updated on June 21, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts