- SirFency compare the indexes each loop then once it gets to the end it should return true or false based on whether or not the MA's have crossed in the last 40 candles.
What you actually do is break out of the loop when you see the first slow above the fast and return false. Look for a cross.
double aPrev = …, aCurr = …, bPrev = …, bCurr = …; bool wasUp = aPrev > bPrev, isUp = aCurr > bCurr, isCross = isUp != wasUp;
-
You set candleNum to zero pre-loop and then increment it at the end of the loop. You also do the same thing in the for statement (variable i) but never use i. Simplify: replace i with candleNum and remove the extra statements.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
So I either do not understand for loops or visibility scope or both. I am just trying to loop through the history of my MA's and make sure they have not crossed over each other in a certain amount of time before I move on to my next criteria checks. For some reason I cant seem to get the loop to work. It's only looking at the loop once. It should be looking at the last 40 MA indexes. I compare the indexes each loop then once it gets to the end it should return true or false based on whether or not the MA's have crossed in the last 40 candles. I highlighted the functions that loop. I also highlighted the print line that keeps showing me that it has only looked at index number 1 in the tester journal.