Positive Integer error when using lowest

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #124300 quote
    CarterCarter
    Participant
    Junior

    Hi,

    I am using the below code as a trailing stop on the US500 but keep getting a positive integer error. When I remove line 9 indicator i5, it seems to work but I dont understand why it doesnt when included.

    I think i have accounted for negatives and also used round() to account for decimals.

    Any help would be appreciated.

    Thanks

    Carter

    i1 = close - 2491//2491 is purchase price, will use postiionprice in backtest
    i2 = 250 - (i1 * 3)//250 is an optimized number
    
    if i2 < 1 then
    i2 = 2
    endif
    
    i4 = round(i2)
    i5 = lowest[10](i4)// to delay fall of lowest value
    
    if i1 > 3 then
    i6 = i5
    else
    i6 = 700//optimized value stop when in loss
    endif
    
    i7 = lowest[i6](low)
    return i7[1]
    #124303 quote
    VonasiVonasi
    Moderator
    Master

    Carter – Please always use the ‘Insert PRT Code’ button when posting code to make it more readable for others. I have tidied up your post. 🙂

    #124305 quote
    CarterCarter
    Participant
    Junior

    Thanks, will do.

    #124309 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Try this at line 8:

    i4 = max(1,round(i2))

    to make sure it’s not 0.

    #124312 quote
    CarterCarter
    Participant
    Junior

    Hi Robert,

    Thanks for that but it seems to the same.

    #124314 quote
    CarterCarter
    Participant
    Junior

    Just something else, it does seem to back test ok but when running on live orders the system SOMETIMES stops with the same error.

    Thanks

    #124315 quote
    VonasiVonasi
    Moderator
    Master

    Try this:

    if barindex > 10 then
    i1 = close - 2491//2491 is purchase price, will use postiionprice in backtest
    i2 = 250 - (i1 * 3)//250 is an optimized number
    
    if i2 <= 1 then
    i2 = 2
    endif
    
    i4 = max(1,i4)//round(i2)
    i5 = lowest[10](i4)// to delay fall of lowest value
    
    if i1 > 3 then
    i6 = i5
    else
    i6 = 700//optimized value stop when in loss
    endif
    
    i6 = max(1,i6)
    i7 = lowest[i6](low)
    endif
    
    return i7[1]
    #124316 quote
    CarterCarter
    Participant
    Junior

    Yes it seems to work, i had to change a couple of values though.

    I tried it with the barindex and with out and it didnt work with out, what is the thought process behind that. I dont understand.

    Thanks for your help

    if barindex > 10 then
    i1 = close - 2491//2491 is purchase price, will use postiionprice in backtest
    i2 = 250 - (i1 * 3)//250 is an optimized number
     
    //if i2 <= 1 then
    //i2 = 2
    //endif
     
    i4 = max(1,round(i2))//round(i2)
    i5 = lowest[10](i4)// to delay fall of lowest value
     
    if i1 > 3 then
    i6 = i5
    else
    i6 = 700//optimized value stop when in loss
    endif
     
    i7 = max(1,i6)
    i8 = lowest[i7](low)
    endif
     
    return i8[1]
    
    #124321 quote
    VonasiVonasi
    Moderator
    Master

    It is a common fix. When you first launch the indicator it checks the first bar and then tries to look for lows on the previous 9 bars that don’t exist. The error message I think is a little incorrect as to how it describes the problem. It is always a good idea to make sure there are enough bars on your chart to actually get a meaningful result.  However if the indicator is used in a strategy then it means that you have a pause at the start of every back test before trading can start.

    Carter thanked this post
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Positive Integer error when using lowest


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Carter @carmac Participant
Summary

This topic contains 8 replies,
has 3 voices, and was last updated by VonasiVonasi
6 years, 6 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 04/02/2020
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...