You're not dumb, it is rather difficult to understand! Using your example and assuming 11 bars in each array: Before the 1st statement, auxCrossedIntermed = "00000000000", After the 1st statement, auxCrossedIntermed = "00000000010"
Before the 2nd statement, CrossedIntermed = "00000000000", and Ref(CrossedIntermed, -1) = "0000000000"... Amibroker effectivley treats the Ref... part of the statement as if it was a temporary copy of the CrossedIntermed statement taken before the 2nd statement began execution (note that there are only 10 elements in this copy array). Changes made to CrossIntermed during the 2nd statement by moving values from AuxCrossedIntermed are not reflected in the copy array. therefore the Ref... clause always copies zero in this scenario. I hope this clarifies it, but as I said before, the same thing got me when I first started out with AB...took me a couple of weeks to finally realise what was going on. --- In [email protected], "nunopires2001" <[EMAIL PROTECTED]> wrote: > > Thanks for the answer. > > To be honest, i am feeling really dumb, since i didn't understand the > explanation. > > Please suppose the following scenario: > > Low[9]=950 > Intermed[9]=970 > High[9]=1000 > > auxCrossedIntermed=IIf(Low< Intermed AND High> Intermed,1,0); > CrossedIntermed=auxCrossedIntermed OR Ref(CrossedIntermed,-1); > > On the bar #10, how will Amibroker evaluate the second formula? > During the evaluation, what will be the values for auxCrossedIntermed > and Ref(CrossedIntermed,-1) ? > > > Best Regards! > > > --- In [email protected], "ian_rosbif" <ian_rosbif@> wrote: > > > > Hi, > > Are you trying use "...OR Ref(CrossedIntermed,-1);" to get the cross > > to persist in CrossedIntermed? In other words, if the cross occurs at > > 11:45, the following 15 elements of Crossintermed should be "1" until > > 12:01, when they should then all have "666" in them? > > > > In which case, the problem lies with the "circular" nature of: > > >>CrossedIntermed=auxCrossedIntermed OR Ref(CrossedIntermed,-1); > > > > auxCrossedIntermed will have a combination of 1s & 0s in it, but > > these aren't actually "moved" to Crossedintermed until the statement > > hase been fully evaluated. Therefore Ref(Crossedintermed, -1) will > > always evaluate to 0 at the time it's executed, even though the 1 > > appears in the array element representing the cross event after the > > statement has been executed. > > > > This is something that drove me mad before I cottoned onto it. > > maybe this would work: > > > > // initialise final values > > CrossedIntermed=IIf(TimeNum()>120000, 666, 0); > > // set cross events > > auxCrossedIntermed=IIf(Low< Intermed AND High> Intermed, 1, 0); > > // cross persists for whole day after it occurs once > > auxCrossedIntermed = Flip(auxCrossedIntermed, True==False); > > // finalise values > > CrossedIntermed=IIf(TimeNum()>120000, 666, auxCrossedIntermed); > > > > If you want the "1" to persist after midday, change the last > > statement to: > > CrossedIntermed=IIf(auxCrossedIntermed, auxCrossedIntermed, > > CrossedIntermed); > > > > > > --- In [email protected], "nunopires2001" <nunopires2001@> > > wrote: > > > > > > Hello, > > > > > > After a encouraging start with Amibroker, i am realizing that > > writing > > > code on AFL is not all that simple... > > > > > > Anyone can explain me what is wrong with these lines of code? > > > > > > CrossedIntermed=0; > > > auxCrossedIntermed=IIf(Low< Intermed AND High> Intermed,1,0); > > > CrossedIntermed=auxCrossedIntermed OR Ref(CrossedIntermed,- 1); > > > CrossedIntermed=IIf(TimeNum()>120000,666,CrossedIntermed); > > > > > > I am working with intraday, 1min data. The market opens at 110000 > > and > > > closes at 193000. > > > > > > I just want to check the CrossedIntermed Value after 12.00h, and the > > > value returned should be: > > > -> 1: If the security crossed Intermed > > > -> 0: Otherwise > > > -> 666: If TimeNum()>120000 > > > > > > > > > Thanks alot! > > > > > >
