Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers, Unverified Users Joined: 10/28/2004(UTC) Posts: 3,111 Location: Perth, Western Australia
Was thanked: 16 time(s) in 16 post(s)
|
Sorry Edwin, I cannot fully grasp what you are trying to achieve, so I will try to explain as I go along, my line of thinking.
1. You want to collect the bars into groups of three, hence we set the "periodicity" for want of a better word here:
prd:=3;
2. Next we want to actually do the group testing. We use the code below, that will return a value of 1 on the first bar in the grouped data, 2 on the second, etc etc and 0 on the last bar.
x:=Mod(Cum(1),prd);
I think up to here we are in agreeance?
3. Now the opening price for the group is the opening price for the first bar in the group (that is when 'x' variable equals 1). We find this bar and return the Open price on this bar as the Open price for the grouped data:
grpO:=ValueWhen(1,x=1,O);
Now as the first bar on the chart also happens to be the first bar in the grouped data, this opening price is valid from the time when Cum(1)=1 i.e. the whole chart. This means the open price in the very first group is identified and displayed in the very first group on the chart.
grpH:=If(x=0,HHV(H,prd),PREV);
grpL:=If(x=0,LLV(L,prd),PREV);
grpC:=ValueWhen(1,x=0,C);
Now all of these values dont get calculated until the group used for there calculation has been "completed" This means, although the open price is displayed in the group for which it is 'valid', the remaining data is 'delayed' until the next group.
To have all of the OHLC data displayed in the group for which it is actually valid, use the Ref() lookahead function to get the data from into the future and plot it in the group for which it pertains.
I think might solve your problem????
prd:=3;
x:=Mod(Cum(1),prd);
grpO:=ValueWhen(1,x=1,O);
grpH:=If(x=0,HHV(H,prd),PREV);
grpL:=If(x=0,LLV(L,prd),PREV);
grpC:=ValueWhen(1,x=0,C);
grpO;
Ref(GrpH,+prd-1);
Ref(GrpL,+prd-1);
Ref(GrpC,+prd-1);
Notice there is now data for the first 'prd' bars on the chart, but not for the last group of chart data is the grouping is not complete i.e. the code will cannot predict the future, the group until it is complete.
[I think there might be a better way to chieve this, but I cannot think of it righ now, but if I do, I will post again.]
It has forward looking referencing, so use it with it caution!
Hope this helps
wabbit :D
|