SebParticipant
Average
Hello, I was trying to convert ZigZag from EasyLanguage to PRT, but PRT doesn’t like the nested loop. Any way around this or shall I give up?
InstanceCntr = 0
InstanceTest = 0
Length = 2
Strength = 1
RightStrength = Strength
LeftStrength = Strength
Highpivotprice = high
Prijs = Highpivotprice
Instance = 1
HiLo = 1
LengthCntr = RightStrength
while LengthCntr < Length and InstanceTest = 0 do
CandidatePrijs = Prijs[LengthCntr]
PivotTest = 1
StrengthCntr = LengthCntr + 1
while PivotTest = 1 and (StrengthCntr - LengthCntr =< LeftStrength) do
if ( HiLo = 1 and CandidatePrijs < Prijs[StrengthCntr]) or ( HiLo = -1 and CandidatePrijs > Prijs[StrengthCntr] ) then
PivotTest = 0
else
StrengthCntr = StrengthCntr + 1
endif
wend
StrengthCntr = LengthCntr - 1
while PivotTest = 1 and (LengthCntr - StrengthCntr <= RightStrength) do
if ( HiLo = 1 and CandidatePrijs <= Prijs[StrengthCntr] ) or ( HiLo = -1 and CandidatePrijs => Prijs[StrengthCntr] ) then
PivotTest = 0
else
StrengthCntr = StrengthCntr - 1
endif
wend
if PivotTest = 1 then
InstanceCntr = InstanceCntr + 1
if InstanceCntr = Instance then
InstanceTest = 1
else
LengthCntr = LengthCntr + 1
endif
endif
wend
if InstanceTest = 1 then
oPivotPrijs = CandidatePrijs
oPivotBar = LengthCntr //+ ExecOffset
Pivot = 1
else
oPivotPrijs = -1
oPivotBar = -1
Pivot = -1
endif
return oPivotPrijs
Nested loops are often a problem for sure with performances of calculation. But I think that you can’t make a straight 1:1 code conversion in that case. The infinite loop problem might come from a wrong interpretation of how the loops are working in the original code with the own platform engine.
As far as I understand that code, it calculates the “pivot” of the last 2 candles including the current one aka Fractals.
There is a nice zigzag code here: https://www.prorealcode.com/prorealtime-indicators/zigzag-indicator/