Tomasz, I have tried like: RES = LastValue( Valuewhen(L <= diff[ barindex ], XM) );
But, it gives error that array subscript has to be a number. Whereas, barindex is array. As you suggested, I tried LastValue, but it will give me values for very last element in array. I want expression to be calculated for every element to get RES values. Is there a way to get BarIndex() subscript as constant? --- In [email protected], "Tomasz Janeczko" <[EMAIL PROTECTED]> wrote: > > Hello, > > ValueWhen as most AFL functions returns array. If you want > single scalar you can use loop or lastvalue > > If you don't want loop (which is actually correct solution), > you may wrap ValueWhen into LastValue. > > RES = LastValue( Valuewhen(L <= LastValue( Valuewhen( index == barindex, diff) ), XM) ); > > Actually even better solution is to address (index) the array directly: > > RES = LastValue( Valuewhen(L <= diff[ barindex ], XM) ); > > Best regards, > Tomasz Janeczko > amibroker.com > ----- Original Message ----- > From: "jay_podda" <[EMAIL PROTECTED]> > To: <[email protected]> > Sent: Tuesday, January 01, 2008 5:57 PM > Subject: [amibroker] Re: Valuewhen > > > > Hi! > > > > The problem with Valuewhen is, in its expression I can only compare as > > many array I want to compare only for that array index. For example, > > > > Current barIndex is 5415 and value of array C and Val is 49.5 and 1.5 > > respectively. Now suppose previous bar with barIndex 4719 has array L > > value of 47.75, which is lower than C-Val of current bar (49.5-1. 5=48) > > . So, I want the value of XM[4719] in my RES array element of > > RES[5415]. > > > > I tried something like: > > > > diff = C-Val; > > index = BarIndex(); > > RES = Valuewhen(L <= Valuewhen(index == barindex, diff), XM); > > > > I thought that inner valuewhen will be executed first, returning > > constant value 48 for outer valuewhen and it will return correct > > value. But, instead it returns value of XM at barindex 3411 where the > > whole valuewhen expression results in true - that is on that bar L is > > < that bars C-Val. > > > > I know that I can do this with loop, but I want to avoid it if > > possible. If I replace Valuewhen(index == barindex, diff) with > > constant 48, it returns correct value. > > > > So, I don't know if I am expecting ValueWhen to do what it's not able > > to. If not, is there any alternative without loop to achieve the same? > > > > > > > > > > --- In [email protected], ChrisB <kris45mar@> wrote: > >> > >> Jay > >> > >> OK just substitute your formula for Val... > >> > >> Val = (EMA(C,30))/30; // or whatever you like. > >> > >> If you are trying to set a threshold based on > >> > >> Threshold = Close today - Val; > >> > >> and then looking back in time to when a Low of any preceding bar > > crossed > >> that threshold, > >> > >> you will need Cross function, but ALSO if I understand you correctly > > you > >> will likely also need to look into Looping. > >> > >> Looping still leaves me stumped but have a look at the files section > > for > >> the articles > >> Looping in Amibroker AFL.pdf and > >> AFL Looping.pdf. > >> > >> Then just use Valuewhen to find the XM. > >> > >> Regards > >> > >> ChrisB > >> > >> jay_podda wrote: > >> > > >> > Chris, > >> > > >> > Thanks for replying so fast. > >> > > >> > In my case, Val is not constant, its array just like C. Also, L > > might > >> > not be ref-1, it can be more than 1 bars ago. And I want to know > > value > >> > of XM corrosponding to bar on which L is less than current bar's > > C- > >> > Val. > >> > > >> > Thanks again, > >> > --- In [EMAIL PROTECTED] ps.com > >> > <mailto:amibroker%40yahoogroups.com>, ChrisB <kris45mar@ ..> > > wrote: > >> > > > >> > > Hi Jay > >> > > > >> > > See if this is what you are looking for: > >> > > > >> > > Val = Param("Val", 1.5 , 1, 3, 0.1); > >> > > > >> > > XM = High;//for argument's sake. > >> > > > >> > > CminusVal = Close - Val; > >> > > Cond1 = Ref(L,-1) < (C-Val); > >> > > myXM= ValueWhen ( Ref(L,-1) < (C -Val),XM); > >> > > > >> > > // run the Exploration to check you values > >> > > Filter = 1; > >> > > > >> > > AddColumn(Val, "Val", 1.2); > >> > > AddColumn( XM,"XM", 1.2); > >> > > AddColumn (C, "close",1.2) ; > >> > > AddColumn(Ref( L,-1),"ref L",1.2); > >> > > AddColumn( CminusVal,"ClessVal ",1.2); > >> > > AddColumn( Cond1, "Cond1", 1.2); > >> > > AddColumn ( myXM, "my XM", 1.2); > >> > > > >> > > // Plot these to visually check > >> > > Plot( myXm,"myXM", colorBlue,1) ; > >> > > Plot( Cond1, "Cond1",colorRed, styleHistogram |styleOwnScale) ; > >> > > > >> > > Regards > >> > > > >> > > ChrisB > >> > > > >> > > jay_podda wrote: > >> > > > > >> > > > I want to find value of array XM when L of very first previous > > bar > >> > is > >> > > > VAL amount less then current bar C. > >> > > > > >> > > > The problem with me is when I use valuewhen, in expression if > > I > >> > use > >> > > > any array for comparision, I can't compare with current bar. > > That > >> > is, > >> > > > if current bar C is 49.50 and VAL is 1.50, I want to get value > > of > >> > XM > >> > > > array when that previous bar's L is less than 48. > >> > > > > >> > > >> > > > > > > > > > > Please note that this group is for discussion between users only. > > > > To get support from AmiBroker please send an e-mail directly to > > SUPPORT {at} amibroker.com > > > > For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG: > > http://www.amibroker.com/devlog/ > > > > For other support material please check also: > > http://www.amibroker.com/support.html > > > > Yahoo! Groups Links > > > > > > > > > > >
