A)
B) Don't use Sleep inside a loop (others may disagree with me on this)
C) You've extracted one bit of your code so we have to guess context - I presume that this code is in start() ?
D) it is intended that start() gets called for each price tick, which is how you EA or indicator will decide that 'something has changed', which is why I stated B) about Sleep usage
E) refactor your code in light of above. maybe check other code examples around here
A)
B) Don't use Sleep inside a loop (others may disagree with me on this)
C) You've extracted one bit of your code so we have to guess context - I presume that this code is in start() ?
D) it is intended that start() gets called for each price tick, which is how you EA or indicator will decide that 'something has changed', which is why I stated B) about Sleep usage
E) refactor your code in light of above. maybe check other code examples around here
Hi Brewmanz,
Thanks for your inputs...It helped me resolve the issue ;)
" it is intended that start() gets called for each price tick " I moved the variable BuyCross out of start() and replaced the while with if operator.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am new to MQL4, Kindly help me debug the following code (Tried back testing, it gets stuck on while loop).
Objective of the code:
1. The code needs to check for crossover.
2. If there is a Cross over, Monitor every next candle for Buy condition.
3. If the Buy Condition is satisfied, Set Value to Order variable and exit loop.
4. If Cross over condition is false exit loop.
+++++++++++++++++++++++++
if (Cross(TsenP, Tsen, KsenP, Ksen) == true) BuyCross = true; // Checks for Cross.
{
while (BuyCross == true) // Loop to be run after Crossover has happened.
{
i = 0;
if (Tsen >= Ksen)
{
if (i >= 0)
{
if (iIchimoku(NULL, 0, T1, T2, Span, MODE_TENKANSEN, i) >= iIchimoku(NULL, 0, T1, T2, Span, MODE_KIJUNSEN, i))
{
i++;
}
if ( Close[i] >= Close[iHighest(NULL, 0, MODE_CLOSE, 26, i)] &&
Pa > iIchimoku(NULL, 0, T1, T2, Span, MODE_TENKANSEN, i) &&
Bull(i) == true) // Check condition to Buy
{
Order = SIGNAL_BUY; //Order is used in the Buy function.
BuyCross = false;
break;
}
}
} else break;
Sleep(10000);
} //End of while
}
+++++++++++++++++++++++++