It might help if you gave some actual code (e.g. what event?). But, if I understand you correctly, then I believe that ValueWhen is the function that you want.
http://www.amibroker.com/guide/afl/afl_view.php?id=163 It will cause all elements from the event onwards to reflect the value at the time of the event, until the next time the event occurs. Mike --- In [email protected], "rselmanl" <no-cents-...@...> wrote: > > > > > Want to fill myArray with a certain value after an event. So far either > increments or just places zero. The goal is to take the value of the > previous myArray value and place it in the current myArray value. Want it to > continue until value changed. Hope this is explained reasonably. > > While in Commentary / Interpration window it might be slower. But don't want > to use loops in backtesting etc. > > Your assistance is appreciated! > > myArray[0] = 3.0; > myArray[1] = 6.0; > myArray[2] = 9.0; //I want to fill myArray with the last entered value > "BarIndex() = " + WriteVal(BarIndex()); //To show index only. > > printf("Before If statement: myArray = %f\n", LastValue(myArray, False)); > if(LastValue(BarIndex(), False) >= 2) > { > myArray = Ref(myArray, -1); //commented stuff is same result. > //myArray[BarCount - 1] = myArray[BarCount - 2]; > //myArray[LastValue(BarIndex())] = myArray[LastValue(BarIndex()) - 1]; > > printf("\nInside If statement: myArray = %f\n", LastValue(myArray, > False)); > printf("\n"); > } > > printf("Outside If statement: myArray = %f\n", LastValue(myArray, False)); > > --- In [email protected], "Mike" <sfclimbers@> wrote: > > > > See Ref function in the user guide. > > http://www.amibroker.com/guide/afl/afl_view.php?name=ref > > > > MyArray = Ref(whatever, -1); // Copy previous bar's values. > > > > Mike > > --- In [email protected], "rselmanl" <no-cents-inv@> wrote: > > > > > > Can someone help? > > > > > > I want to copy the previous bars value into the current bar. E.G. > > > myArray[BarCount - 1] = myArray[BarCount - 2]; > > > This starts incrementing the array value. > > > Of course I wait until there are enough values to make the move. > > > Please see below (the last couple of lines especially). > > > > > > Your help is appreciated! > > > > > > -Ron > > > > > > "BarCount() = " + WriteVal(BarCount); //Not relevant ~16K bars... > > > "BarIndex() = " + WriteVal(BarIndex()); //Think this is location in > > > array. > > > > > > myArray[0] = 2.0; > > > myArray[1] = 2.0; > > > myArray[2] = 2.0; > > > myArray[3] = 2.0; > > > myArray[4] = 1.0; > > > myArray[5] = 1.0; > > > myArray[6] = 1.0; > > > myArray[7] = 5.0; > > > myArray[8] = 5.0; > > > myArray[9] = myArray[4]; > > > myArray[10] = 5.0; > > > myArray[11] = 5.0; > > > myArray[12] = 5.0; > > > myArray[13] = 5.0; > > > myArray[14] = 5.0; > > > myArray[15] = 5.0; > > > myArray[16] = 5.0; > > > myArray[17] = 5.0; > > > myArray[18] = 5.0; > > > myArray[19] = 5.0; > > > myArray[20] = 1.0; //above is okay it seems. > > > > > > > > > if(LastValue(BarIndex(), False) > 15) > > > { //printf statements seem to work. > > > printf("\nmyArray[Lastvalue(BarIndex(), False) - 3] = %f\n", > > > myArray[LastValue(BarIndex(), False) - 3]); > > > printf("myArray[Lastvalue(BarIndex(), False) - 2] = %f\n", > > > myArray[LastValue(BarIndex(), False) - 2]); > > > printf("myArray[Lastvalue(BarIndex(), False) - 1] = %f\n", > > > myArray[LastValue(BarIndex(), False) - 1]); > > > printf("myArray[Lastvalue(BarIndex(), False) - 0] = %f\n", > > > myArray[LastValue(BarIndex(), False) - 0]); > > > myArray[BarCount - 1] = myArray[BarCount - 2]; //same problem on next > > > line. > > > // myArray[LastValue(BarIndex())] = myArray[LastValue(BarIndex()) > > > - 1]; > > > } > > > //a plot statement will also increment and then drop to zero. > > > printf("\nLastValue(myArray, False) = %f\n\n", LastValue(myArray, False)); > > > > > >
