looping problem

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #90571 quote
    chook
    Participant
    New

    I am a newbie, and can’t get the attached code to work.

    It just yield zero line.

    It is my attempt to translate code from amibroker.

    Please help.

    Xlength = 5
    Length = 18
     
    Synthetic = Xlength * Length
    Value1 = lowest[synthetic](Low)
    Value2 = highest[synthetic](High) - Value1
    
    If Value2 > 0 then
    XTK = (Close - Value1)/Value2 * 100.0
    else
    XTK = 0
    endif
    
    for i = 0 to BarIndex do
    if i >= Xlength then
    XTDF = XTDF[i-Xlength] + 0.5 *( XTK[i] - XTDF[i-Xlength])
    else
    XTDF = 0
    endif
    next
    
    Return XTDF coloured(100,100,0) as "XTDF"
    
    #90584 quote
    robertogozzi
    Moderator
    Master

    I didn’t check the calculations, yet.

    Still I can see you are using very time consuming loops.

    BARINDEX will soon exceed a value of several thousands units… slowing (if not freezing at all) your system quite much. I can’t figure out why you weren’t reported an error message by the system!

    #90606 quote
    robertogozzi
    Moderator
    Master

    The result is always ZERO because the initial value of XTDF is 0 and you ALWAYS end up there because your loop backwards will always end up catching the value tied to variable i which will always go back i times to when the code started.

    chook thanked this post
    #90807 quote
    chook
    Participant
    New

    Thank you for your help

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

looping problem


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
chook @chook Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by chook
7 years, 1 month ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 02/06/2019
Status: Active
Attachments: No files
Logo Logo
Loading...