Code of series of periods

Viewing 15 posts - 1 through 15 (of 25 total)
  • Author
    Posts
  • #75475 quote
    maximus78
    Participant
    Senior

    Good morning,

    is there anybody who knows if there’s an easier way to write this code, in which the actual close is > or < of a series of previous close like this?

    close>close[1] and close>close[2] and close>close[3] and close>close[4] and close>close[5]....

    I need to put in a backtest with a variable X,  that is the last of the series,

    if X is 5 then .....close>close[1] and close>close[2]....till close>close[5]

    Thanks so much

    Maxx

    #75477 quote
    Vonasi
    Moderator
    Master
    x = 5
    
    count = 0
    for i = 1 to x
    if close > close[i] then 
    count = count + 1
    endif
    next
    
    if count = x then

    EDIT: Code is now corrected as discussed further down in this thread.

    #75480 quote
    robertogozzi
    Moderator
    Master

    What about

    IF close > highest[5](close[1]) THEN...

    ?

    #75482 quote
    Vonasi
    Moderator
    Master

    As usual I make the job harder than it needs to be! 🙂

    #75484 quote
    Nicolas
    Keymaster
    Master

    As for the Vonasi’s code, ‘count’ variable should be reset to 0 before the FOR/NEXT loop, otherwise it will endlessly increase.

    #75491 quote
    Vonasi
    Moderator
    Master

    As for the Vonasi’s code, ‘count’ variable should be reset to 0 before the FOR/NEXT loop, otherwise it will endlessly increase.

    So not only harder but it doesn’t work! Why do in one line what you can do in 8. I blame it on the heat…..

    #75498 quote
    GraHal
    Participant
    Master

    But don’t both code options fail to give the OP what he wants?

    OP wanted close of bar 1 > close of bar 2 and close of bar 2 > Close of bar 3 etc … put another way 5 bars with a increasing value of Close?

    #75500 quote
    Vonasi
    Moderator
    Master

    OP wanted close of bar 1 > close of bar 2 and close of bar 2 > Close of bar 3 etc … put another way 5 bars with a increasing value of Close?

    That is not what he wrote – he wrote this:

    close>close[1] and close>close[2] and close>close[3] and close>close[4] and close>close[5]....
    #75501 quote
    robertogozzi
    Moderator
    Master

    He always compared CLOSE, not CLOSE[previous bar].

    Anyway, that would be

    IF summation[5](close > close[1]) = 5 THEN....
    #75502 quote
    GraHal
    Participant
    Master

    That is not what he wrote – he wrote this:

    Hahaha the heat is getting to all of us, I got it locked in my mind from initial reading  (I should have reread) that he wanted an increasing value of close.

    Cheers

    #75503 quote
    Vonasi
    Moderator
    Master

    …. and I first wrote that summation code that Robert just posted but then deleted my post when I realised my mistake and then went on to post a very complicated method that didn’t work! It is definitely the heat.

    #75507 quote
    maximus78
    Participant
    Senior

    Thanks guys for the replies,  yes Roberto’s code is correct, I have verified.

    My mind was blocked too….actually it was so simple!

    Maxx

    #75516 quote
    GraHal
    Participant
    Master

    CLOSE[previous bar]. Anyway, that would be

    Code added to Snippet Link Library

    #104152 quote
    robertogozzi
    Moderator
    Master

    Sorry for reviving this old topic, but after thinking it over and with a whole additional year experience… VONASI was right (apart from resetting count to 0 at line 2 as suggested by Nicolas).

    My code always compares the current candle to the previous one, which is not exactly what maximus78 wanted. Indeed I believed using CLOSE without brackets would do, but summation reads it as being CLOSE[0], then it shifts both every iteration, so that the next one would be CLOSE[1] compared to CLOSE[2] and so on. CLOSE does NOT remain CLOSE[0] thus making a loop necessary.

    #104154 quote
    Vonasi
    Moderator
    Master

    VONASI was right

    Finally almost thirteen months later I get the recognition that I deserve. I’ve had trouble sleeping at night ever since I posted something that was thought to be wrong. Thank goodness that nightmare is now over. 🙂

    Strangely maximus78 was happy with your code Roberto so perhaps what he wanted and what he described were actually different things? It wouldn’t be the first time someone did that on the forums!

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

Code of series of periods


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
maximus78 @maximus78 Participant
Summary

This topic contains 24 replies,
has 5 voices, and was last updated by Vonasi
6 years, 6 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 07/06/2018
Status: Active
Attachments: 3 files
Logo Logo
Loading...