Thanks Mike, I try it.
--- In [email protected], "Mike" <sfclimb...@...> wrote: > > I'm not sure that I entirely understand your question. But, try > something like this: > per = 10; > xxx = High - Low; // Use any expression you want > diff = 0; > cont = NZ(null, null); > > currentBar = BarCount - 1; > firstBar = max(0, currentBar - per); > > for (bar = currentBar - 1; bar >= firstBar; bar--) { > if (xxx[bar] > diff) { > diff = xxx[bar]; > cont[bar] = (currentBar - bar); > } else { > diff = iif(bar > firstBar, xxx[bar - 1], 1); > cont[bar] = cont[bar + 1]; > } > } > > Plot(xxx, "XXX", colorBlue, styleBar); > Plot(cont, "CONT", colorRed, styleStaircase | styleOwnScale); > Mike > --- In [email protected], "angio" <angio1967@> wrote: > > > > hello guys, > > can someone help me to write this loop for an indicator, there are > many days that I try but I can't do !!! > > > > - the beginning of the loop is the bar before today > > - the loop length is the variable PER (for example 10) > > > > *** Then the loop works from BAR -1 to BAR -10 *** > > > > PER=10; > > > > XXX= my expression; > > > > DIFF=0; set variable to 0 > > CONT=0; set variable to 0 > > > > in the loop: > > > > If XXX > DIFF > > then DIFF = XXX > > and CONT assumes the number of backwards bar in the loop > > > > for example: > > > > BAR -1 XXX > 0 cont = 1 > > BAR -2 XXX > diff cont = 2 > > BAR -3 XXX > diff cont = 3 > > BAR -4 XXX > diff cont = 4 > > BAR -5 XXX > diff cont = 5 > > BAR -6 XXX > diff cont = 6 > > BAR -7 XXX < diff cont = 6 break loop, CONT assumes 6 > > BAR -8 XXX < diff cont = 6 > > BAR -9 XXX > diff cont = 6 > > BAR -10 XXX > diff cont = 6 > > > > The main problem is how to set the beginning of the loop and how to > assign values to the arrays earlier in reverse from the usual. > > > > I hope I was clear, thanks for the reply. > > Angio > > >
