Nested loops problem

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #214510 quote
    Seb
    Participant
    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
    #214518 quote
    Nicolas
    Keymaster
    Master

    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/

    Seb thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Nested loops problem


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Seb @seb Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Nicolas
2 years, 9 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 05/11/2023
Status: Active
Attachments: No files
Logo Logo
Loading...