Hi Guys,
hoping for some help the indicator looks fine but when i go to put it on the chart it throws the error “an infinite loop or a loop with too many iterations was detected”.
Essentially i want to place an arrow at the start of a pattern where the series of candles open is less than the close until it isn’t. i want to count the number of pips that have occurred from the first candle in the series until a candle closes lower than the open BUT i only want to plot an arrow if 3 or more candles show up. apologies if this confusing i am reasonably new to this and not sure how to explain it easily. hope this makes sense?
// Define variables
CountPoints = 0 // Counter for consecutive candles where open < close
TotalPips = 0 // Total pips counted
StartPrice = 0 // Price of the first candle that meets the condition
FirstCandleIndex = -1 // Index of the first candle where counting starts
CurrentBar = 0 // Variable to track current bar index
// Initialize variables
CountPoints = 0
TotalPips = 0
StartPrice = 0
FirstCandleIndex = -1
CurrentBar = 0
// Main loop to iterate through bars
while CurrentBar < BarIndex do
// Check condition: open < close for the current bar
if Open < Close then
// If this is the first candle that meets the condition, record its price and index
if CountPoints = 0 then
StartPrice = Open
FirstCandleIndex = CurrentBar
endif
// Increment counter
CountPoints = CountPoints + 1
// Calculate pips from the start price to current bar close
if CountPoints > 1 then
TotalPips = TotalPips + (Close - Open) / PointSize
endif
else
// Check if we've counted more than 3 consecutive candles
if CountPoints > 3 then
// Plot arrow on the first candle where counting started
DrawArrowUp(FirstCandleIndex, Low[FirstCandleIndex] - 10*TickSize)
endif
// Exit loop if condition is not met
endif
wend
// Move to the next bar
CurrentBar = CurrentBar + 1
// Output the total pips counted
PRINT(TotalPips)
return
Move the CurrentBar = CurrentBar + 1 , inside the loop, before wend.
The statement after ‘While’ is the condition to exit the loop. There needs to be some sort of loop counter to reach the condition.
Since the ‘above line’ is outside the loop, CurrentBar is not incremented, loop cycles till error message.