Hi coders
I'm a beginner of coding. I created two simple loops with break; to get the 1st shift of 3 green bars, use both i-- and i++.
For i-- loop, I can only get the bar10 (start of the loop) output if 3 green bars happen on bar10, why this loop cannot give an answer from bar9 to bar1 despite there are 3 green bars ?
For i++ loop, I can only get the bar1 (start of the loop) output if 3 green bars happen on bar1, why this loop cannot give an answer from bar2 to bar10 despite there are 3 green bars ?
Where I went wrong on the codes ? What are the correct ways to write the codes ? Kindly advise and write down your codes for my testing, thank you.
I'm a beginner of coding. I created two simple loops with break; to get the 1st shift of 3 green bars, use both i-- and i++.
Inserted Code
int grnBarASf=0; for(int i=10; i>=1; i--) { double cOp0=iOpen(symbol,60,i), cOp1=iOpen(symbol,60,i+1), cOp2=iOpen(symbol,60,i+2), cCs0=iClose(symbol,60,i), cCs1=iClose(symbol,60,i+1), cCs2=iClose(symbol,60,i+2); if(cOp0<cCs0 && cOp1<cCs1 && cOp2<cCs2) grnBarASf=i; break; } //+------------------------------------------------------------------+ int grnBarBSf=0; for(int i=1; i<=10; i++) { double cOp0=iOpen(symbol,60,i), cOp1=iOpen(symbol,60,i+1), cOp2=iOpen(symbol,60,i+2), cCs0=iClose(symbol,60,i), cCs1=iClose(symbol,60,i+1), cCs2=iClose(symbol,60,i+2); if(cOp0<cCs0 && cOp1<cCs1 && cOp2<cCs2) grnBarBSf=i; break; } {Alert(symbol+" Sf -- || ++ : "+IntegerToString(grnBarASf)+" || "+ IntegerToString(grnBarBSf));}
For i-- loop, I can only get the bar10 (start of the loop) output if 3 green bars happen on bar10, why this loop cannot give an answer from bar9 to bar1 despite there are 3 green bars ?
For i++ loop, I can only get the bar1 (start of the loop) output if 3 green bars happen on bar1, why this loop cannot give an answer from bar2 to bar10 despite there are 3 green bars ?
Where I went wrong on the codes ? What are the correct ways to write the codes ? Kindly advise and write down your codes for my testing, thank you.