how do I loop back to save price and bar index between two points

Forums ProRealTime English forum ProBuilder support how do I loop back to save price and bar index between two points

Viewing 14 posts - 1 through 14 (of 14 total)
  • #206400

    Could somebody please advise. I am completely stuck. I am trying to store the last high over a specific period(but not including the current bar),once a condition is met. Then save both the bar index of the bar that has the high on it and the high price. So that both may be referenced later.

    I am guessing it is a loop but I don’t know how to create a loop that starts looking for the high only from the previous bar. I think I need to store the value and the bar index in arrays but again I am not sure.  I have attached a picture to show exactly what I mean.

    Please excuse the repetition in the question and diagram I just want to be clear so as not to waste anybodies time.

     

    many thanks in advance

     

    #206429

    Yes, you need to loop through the past bars:

     

    1 user thanked author for this post.
    #206432
    JS

    Hi @blackwing

    Maybe this will help you too…

    I have chosen as an (example) condition for a “crosses over” …

    When this condition is true, I have the following results stored in an array:

    The point at which the crossing takes place, the price (high) of the crossing and the distance in bars compared to the previous crossing…

    Regards Jaap

    1 user thanked author for this post.
    #206654

    Hi Roberto,

    Thank you for the loop instruction that has helped me a lot!

    It has taken me a while to figure this one out. I couldn’t get your elegant code to work correctly, when I run it, it is showing multiple high points and does not include the previous condition bar in the calculation.(image1).

    However using your loop structure and adding my very not elegant code I got it working (image2). But this feels rather clunky. Do you have a better way? Or am I missing something completely?

    Also how do you recall the HHPrice from the past. ie. 3rd last HHPrice not HHPrice[3]  value from 3 bars ago.

    Many thanks again.

     

    #206672

    Thank you @JS,

    That is super helpful.

    I have one more question I am having trouble recalling the the values stored in the array. How do I recall the last [n] value of the $ResultPrice.

    In your example, how would I recall the $ResultPrice the last time the cross occurred or the $ResultPrice[n]th last time it occurred, I am sure it is simple but I can’t seem to grasp it.

    Many thanks in advance

    #206676
    JS

    Hi @blackwing

    Just type “$ResultPrice[0]” after the Return…

    The $ResultPrice is the “High” of the last crossing…

    1 user thanked author for this post.
    #206692

    Thanks again @JS

    I am still confused. My apologies if I am being slow.

    Returning “$ResultPrice[0]” after the Return is all good. But when I try “$ResultPrice[1]” it does not give the value prior to the “$ResultPrice[0]” but just moves it along one bar, also when I run your programme I get the attached image. With the plot of the average only going back one bar this seems to be a similar issue.

    I am trying to recall several past values and plot them. My understanding of an $Array was that each saved value of it is stored, but I can’t seem to recall them later. For example how do I plot the 3rd value ago of the crossover, rather than the value of the last crossover 3 bars ago?

    In the attached image I am returning “$ResultPrice[0], $ResultPrice[3]”

    Many thanks

    #206697
    JS

    Hi @blackwing

    Probably most of the forum agrees with me when I say that understanding programming with arrays is one of the most difficult things, so it’s not your fault…

    In the code, the Index is related to the crossings, Index=1 is crossing 1 and so on, and these crossings have several data such as the bar index and the price, but these only belong to these crossings…

    What I added is the Close of each crossing and to meet your request there is an additional variable called “xPriceBefore” and when you give it a certain values like for example 3, then the code plots the value of the close three bars for the first crossing…

    I can’t make it any more fun… 😉

    #206745

    Thank you @JS

    Oh my goodness.You have just made my head explode!

    You have probably answered this question, my apologies but I still don’t understand. I am trying to keep track of the last 3 or 4 values (and barindex) of the saved point (crossing, in your example), plot them and then use them in code later.

    So if I simply wanted to see if C< C1 and C1<C2 where C are the last instances of Crossing. How do I do that? (diag1.)

    Many thanks

    #206751
    JS

    Hi @blackwing

    Here’s the simple version… 😉

    You can retrieve the values of the Close and the BarIndex of the first intersection with:

    $xClose[0] and $xBarIndex[0]

    And of the previous crossing with:

    $xClose[1] and $xBarIndex[1]

    And so on…Hi @blackwing

    #206763

    Thank you @JS

    Looks simple but ?

    Please could you plot this image. Because when I try with either of the following  it doesn’t work

    Many thanks in advance

    #206782
    JS

    Hi @blackwing

    Final touch…

    1 user thanked author for this post.
    #207103

    Dear Jaap @JS

    Thank you very much indeed!

    1 user thanked author for this post.
    avatar JS
    #207143

    But when I try “$ResultPrice[1]” it does not give the value prior to the “$ResultPrice[0]”

    I don’t think it will help you much, but for understandings : with arrays you can’t ask for the previous value of an element in it (or for the previous value of the whole array).

     

    Probably most of the forum agrees with me when I say that understanding programming with arrays is one of the most difficult things, so it’s not your fault…

    Agreed. But it is not the programming with arrays which is dificult – it is the way PRT implemented it (and this is not about not being able to ask for the previous bar value (as in [1])). If only the arrays would be multi dimensional most of the issues *I* have with arrays in PRT would be gone. This is not because I need more dimensions, but because it would allow for making clear what you are doing with them. This in itself is hard to explain, but you can simply know when you are used to a normal environment with arrays.

    Hats off to those like you, Jaap, who can utilise arrays within PRT. I never came further than using the available means without arrays, accomplishing the same (knowing that everything and all already *are* arrays (the [1], [2], [3] thing) and that you can let loose all functions (e.g. Average) on that too – which is not even possible with arrays (last time I looked)).

Viewing 14 posts - 1 through 14 (of 14 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login