Loop to delete

To add comments, please log in or register
peterpies
33
peterpies  

Hi

Trying to create a loop to check for a condition then act if meet. The loop does not seem to count down when I use print("i=",i); to error check

// delete 1W1 high if any more recent D1 high is higher


datetime open0W1=iTime(Symbol(),PERIOD_W1,0); // find open bar of the week
int shift=iBarShift(NULL,PERIOD_D1,open0W1); // shift it to the D1 bar

for (int i=shift;i>1;i--) // create loop starting from first D1 bar of the week and count back to bar 1
{
if (iHigh(NULL,PERIOD_D1,i)>iHigh(NULL,PERIOD_W1,1)) // check if any D1 high is higher than W1 high 
ObjectDelete(0,"1HighW1"); // action 
}


lippmaje
856
lippmaje  
W1 bars start on Sundays. For D1 there's no Sunday so you get the bar of the previous week's Friday. So the loop should start with shift-1 and that's it, rest looks ok.
peterpies
33
peterpies  

Thanks for the reply.

Funny I realized that mistake while out walking, it's great for that.

Before though I used,

Print(" i=", i);

And it was stuck on 2 and not printing 1

I have changed this since, but can't see what difference >= would make. It's working know anyway.

for (int i=shift;i>=1;i--)

And added,

shift=shift-1;
To add comments, please log in or register