Hello,
i read about the problem with PRT Engine and for in for loops. I have the following indicator and want to run it in my ProScreener.
Problem: i get the infinite loop error.
How can i solve this?
DEFPARAM CALCULATEONLASTBARS = 500
timeRange=200
result=0
searchLeftOffset1=5
searchLeftOffset2=20
//check if actual close is near highest close in timeRange
if close > 0.97*highest[timeRange](close) AND close < 1.02*highest[timeRange](close) then
//if so, search for next close within timerange, that meets the same criteria. Start search searchLeftOffset1 Days before
for z = searchLeftOffset1 to timeRange do
if close[z] > 0.96*highest[timeRange](close) AND close[z] < 1.02*highest[timeRange](close) then
//if second day found, search for next close within timerange, that meets the same criteria. Start search searchLeftOffset2 Days before
for y = z + searchLeftOffset2 to (timeRange) do
if close[y] > 0.96*highest[timeRange](close) AND close[y] < 1.02*highest[timeRange](close) then
result=1
endif
next
endif
next
else
result=0
endif
return result
Thank you
Best regards,
Branimir
Too many iterations, almost 40K per candle!
Try removing line 1 and setting 50K units, to allow enough bars to run.
It will take quite a long time to calculate!
I removed line 1, used 10K units and set timerange=50, and it worked!
You can try to encapsulate your loop into a condition with “IsLastBarUpdate”, so that the code is only once each time the last bar is updated (new price received), see:
IsLastBarUpdate
Speed calculation with IsLastBarUpDate instruction