Bars Since a Previous Event Condition

Hello

I am trying to recreate a TC2000 scan as outlined on the WishingTree blog webinar called YellowBand. The code is scanned in daily but includes weekly and monthly timeframes. I think managed the majority of conditions except for one:

The monthly (yellowband1): the stock has made a monthly bar all-time high 2 bars ago, and has spent 1 or 2 months consolidating, so the recent bar is below the ATH value. I tried many options using ValueWhen and HHVBars - but can't figure it out.

wc = TimeFrameCompress( Close, inWeekly );	
mc = TimeFrameCompress( Close, inMonthly );

Yellowband1 = Ref(mc,-2) > HHV(mc,100) AND mc < Ref(mc,-2);
Yellowband2 = wc > MA(wc,10) AND MA(wc,10) > MA(wc,30) AND MA(wc,4) > MA(wc,10);
Yellowband3 = StochD(10,1) <= 25 OR StochD(10,1,1) <= 25 OR StochD(10,1,2) <=25;
Yellowband4 = C > Ref(C,-1);
Yellowband5 = StochD(1,1) >= 40;

Yellowband = Yellowband1 AND Yellowband3 AND Yellowband3 AND Yellowband4 AND Yellowband5;

I guess my questions are

Is the correct way to source other timeframe data?

And what is the best way to identify and chain events, so something like if Y occurs with X bars, and now Z happens within W bars, trigger true?

Thanks

First and foremost - carefully read: Multiple Time Frame support

Especially orange boxes. You will learn that you have to use TimeFrameExpand

Secondly read AFL Function Reference - BARSSINCE

Thanks for the references. Have I applied it correctly?

wc = TimeFrameCompress( Close, inMonthly );
TimeFrameSet( inWeekly );
w4ma = MA(wc,4);
w10ma = MA(wc,10);
w30ma = MA(wc,30);
wc = TimeFrameCompress( Close, inWeekly );	
TimeFrameRestore();

Yellowband1 = wc > TimeFrameExpand(w10ma,inWeekly) AND TimeFrameExpand(w10ma,inWeekly) > TimeFrameExpand(w30ma,inWeekly) AND TimeFrameExpand(w4ma,inWeekly) > TimeFrameExpand(w10ma,inWeekly);

mc = TimeFrameCompress( Close, inMonthly );
TimeFrameSet( inMonthly );
ATH = Ref(mc,-2) > Ref(HHV(mc,260),-3);
TimeFrameRestore();

Yellowband2 = TimeFrameExpand(ATH, inMonthly );
Yellowband3 = mc < Ref(mc,-2);

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.