troubles with IIF functions

#1
dear all,
please, help me with this problem.
I want the array 'trial' = 10 from the bar 10 till to the end.

this my attempt:
trial=1;
trial =IIf (BarIndex()==10, 10, Ref(trial,-1));


it happens that just the bar 10 is = 10. But from the 11th bar till to the end the value of 'trial' array is =1 :confused:


Maybe the problem come from the first row, where I initialize the array. It is read for each bar, so each time is deleted the value assigned with IIF function.

So the question is: how can I iniziatialize the array 'trial' just one time avoiding the same row is read at each bar?.

thank you

Cippo
 
Last edited:

KelvinHand

Well-Known Member
#2
dear all,
please, help me with this problem.
I want the array 'trial' = 10 from the bar 10 till to the end.

this my attempt:
trial=1;
trial =IIf (BarIndex()==10, 10, Ref(trial,-1));


it happens that just the bar 10 is = 10. But from the 11th bar till to the end the value of 'trial' array is =1 :confused:


Maybe the problem come from the first row, where I initialize the array. It is read for each bar, so each time is deleted the value assigned with IIF function.

So the question is: how can I iniziatialize the array 'trial' just one time avoiding the same row is read at each bar?.

thank you

Cippo


trial =IIf (BarIndex()<10, 1, 10); OR

trial =IIf (BarIndex()>=10, 10, 1);
 
#3
trial =IIf (BarIndex()<10, 1, 10); OR

trial =IIf (BarIndex()>=10, 10, 1);
thak you kelvin, I understand my example was too easy and didn't highlight the real problem.
Let me try to better explain my problem:

trial=1;

valuewhenbarindex10=valuethatchanceateachbar
trial =IIf (BarIndex()==10, valuewhenbarindex10, Ref(trial,-1));

I want to use ref(trial, -1) function because I want trial variable keeps the value when bar is 10, for bar 10 ahead.

thank you

Cippo
 

Similar threads