How we calculate bi-weekly close and high?

Is this correct?

dow = DayOfWeek();
lastDayofWeek = dow > Ref( dow, 1 );

startpoint = lastDayofWeek  AND Cum( lastDayofWeek ) % 2 == 0;

// Two week(bi-weekly)closing price
twoWeekClosingPricecomp = SparseCompress( startpoint, Close );
twoWeekClosingPriceEx = SparseExpand( startpoint, comp );

//Two week(bi-weekly) Highest Price
twoWeekHighestHigh = HighestSince( startpoint, High );
twoWeekHighestHighPricecomp = SparseCompress( startpoint, twoWeekHighestHigh );
twoWeekHighestHighPriceEx = SparseExpand( startpoint, twoWeekHighestHighPricecomp );

This might be correct, but you could get it easier using TimeFrameGetPrice() function.

As a side note, when you are posting for the very first time, it is not bad idea to introduce yourself. Also 3 word question like β€œis this correct?” in a very first post is considered rude. If you want someone to help you, be polite. Something like β€œHi I am new here. Could anybody tell me if the code I got is correct. I am not sure because …”.

1 Like