question about for(i=1;i

 

does this mean i is incremented by the value of pos on each cycle of the for statement ?

for(i=1;i<=MA_Period;i++,pos--)

 

Hi SDC,

I didn't know you could do this........anyway, this is all I could find.

Expressions separated by commas are calculated left to right. All side effects of calculations in the left expression can only occur before the right expression is calculated. The type and value of the result coincide with the type and value of the right expression.

for(i=0,j=99; i<100; i++,j--) Print(array[i][j]); // Loop statement
In this case the loop will run from 0 to 99 with j = 99, then it will run from 0 to 99 with j = 98....etc, etc
 
SDC:

does this mean i is incremented by the value of pos on each cycle of the for statement ?

for(i=1;i<=MA_Period;i++,pos--)

I means I is incremented each cycle and pos is decremented each cycle
 

Hi Kenny, yes I didnt know you could do this either, I found it in the source code for moving averages my first guess was wrong though I found by adding these alerts what happens is, i increments while pos decrements, this must mean you can have several veriables in the for statement increasing and drecrementing at the same time.

I'm working on modifying the moving averages to give it an applied to price external input like the regular built in one, and I want to give it some new ones like I was thinking maybe an open/open/high/low would be like a weighted open that might be faster than a weighted close, while still allowing some repainting as the highs and lows on the lower timeframe charts affect it.

   if(pos<MA_Period) pos=MA_Period;
   for(i=1;i<=MA_Period;i++,pos--)
     {
      price=Close[pos];
      sum+=price*i;
      lsum+=price;
      weight+=i;

      Alert("i = ",i);
      Alert("pos = ",pos);
      Alert("lsum = ",lsum);
      Alert("weight = ",weight);
     }

Results of this loop in a 4 periods LWMA:

Alert: i = 1
Alert: pos = 4
Alert: lsum = 1.287
Alert: weight = 1

Alert: i = 2
Alert: pos = 3
Alert: lsum = 2.5746
Alert: weight = 3

Alert: i = 3
Alert: pos = 2
Alert: lsum = 3.8622
Alert: weight = 6

Alert: i = 4
Alert: pos = 1
Alert: lsum = 5.1484
Alert: weight = 10

 
WHRoeder:
I means I is incremented each cycle and pos is decremented each cycle

yes, and it makes me wonder what else you can do with for loops in the header
Reason: