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-...@...> 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)); >
