Indicator projecting past candles into the future

Forums ProRealTime English forum ProBuilder support Indicator projecting past candles into the future

Viewing 10 posts - 1 through 10 (of 10 total)
  • #233475

    Hi there @ProRealCode!

    (I’m new to this forum and this is my first post, so hopefully I’ve choosen the correct place to post it. If not, please feel free to move it.)

    I’m about to create an indicator that will project past candle patterns (based on a defined search pattern – which I’ll come back to later) into the future – after the current candle so to speak.

    As ProBuilder is giving me a hard time doing so, I’d like to place some questions first.

    So my initial two questions would be:
    1. Is it possible to draw a variable amount of candles (i.e. 7-20) ‘after’ the current candle?

    2. If yes, how could I do it?

    My challenges:
    Saving the open, high, low, close within defined arrays. Honestly I wasn ‘t able to debug my arrays and see if this works in the first place.
    The result is always the same: I receive a single candle. It’s always the candle with the highest index of that array. But I’m missing the previous saved candles. So if my number of candles would be 7, I always receive candle no. 7 but not 1-6.
    Furthermore the candle is always printed at the same spot of the current candle and not the spot/s following after.

    My code so far:

    Attached you’ll also find two screenshots, one to show how it looks like and one how it is supposed to look like if working correct.

    Any help, solution,… is highly appreciated.

    Thank you in advance.

    Best regards,
    Florian

    #233479

    Hi,

    the issue is because the drawcandle command is only on same barindex the code is read.

    Instead, you could go for now with the following workaround: using the drawsegment command, once with a bigger thickness for candle body, and twice with smaller thickness for both candle wicks (or once from low to high if same color to avoid potential overlap effects), and placing those onan x coordinate being bardindex+N, N being the number of candles in the future of the current one.

    https://www.prorealcode.com/documentation/drawsegment/

    adding the option at the end style(line,thickness), thickness being an integer between 1 and 5 (option not in the doc page above as it appeared some time later), line could also be dottedline and its variants, but I assume you’ll want a line.

    DRAWSEGMENT(x1,y1,x2,y2) COLOURED(R,V,B,a) style(line,thickness)

    For later, a request I placed some time ago could become handy for a future slightly more inetresting workaround… It is in “the right hands”, and it “might” be granted (I prefer to wait until informed of next updates before considering it’s coming for sure), and it would result in being able to access x coordinate “between” 2 barindex for a graphic object moving if scrolling or zooming. If that happens, then the better workaround would become using a drawrectangle for body and a drawsegment for wicks.

    There could also be more directly: placing a request to be able to drawcandle anywhere, asking for a 5th optional parameter for position.

    But for now, I’d pragmatically stick with 1st workaround above, to be able now to draw your patterns in the future, not just for an end result, but first to really visualise what your code is doing to debug it more easily .

    3 users thanked author for this post.
    #233484

    Hi JC,

    thank you for your fast response.

    To make sure I understand it correct, my assumptions would be:

    currently it is not possible due to the fact that the function ‘drawcandle” will not move through the different indices with no option of shifting it incrementally by 1. Correct?

    I furthermore assume, my arrays are each correctly ‘filled’ with the last 7 open’s, high’s, low’s and close’s, correct?

    So before taking action on the workaround you supposed I would have one more essential question (of course to all readers around):

    is it possible to search the historic data for a similar pattern as stored within the arrays?

    Thanks again,
    Florian

    #233495

     

    Hi,

    Based on you code and  JC’s comments try this.

     

     

    2 users thanked author for this post.
    #233570

    Hi druby,

    this is awesome!

    If I would like to search for that pattern in historic data (i. e. the past 1,000 candles), the following questions arise:

    1. Is there maybe any kind of ‘pattern’-detector already included in ProBuilder?

    2. Does ProBuilder support any kind of function to accomplish my task or would I have to hard-code it into the indicator?

    Again, any helpful information and support is highly appreciated 🙂

    Thanks all.

    regards,
    Florian

    #233642

    Hi…

    Compiled two long reply and for some reason lost both.

    Code below is a starting point for pattern recognition I’ve been working on. 6 bar pattern bull, bull, bear, bear, bull, bull

    You need to break down specifically what variables of the pattern are required to define it.

    Along with the reasoning of the process of what your trying to do.

    Logic takes no prisoners! , but can take you on a long journey and dump you somewhere!

    druby

     

     

    1 user thanked author for this post.
    #233990

    Hey druby,

    first of all: thank you again and you’re so right. I got completely lost with your last suggestion. Not understanding, what exactly the outcome will be.

    Maybe I did not explain what I really want to do as accurate as it might be needed.

    So here we go:

    1. I want to define a range between 3-7 (max. 10) candles. I will draw a rectangle around those candles (only for visualization purposes).
    2. I’ll save the data (3-7 candles in total) from step 1 into an array like: write a ‘1’ if the candle is green (open < close); write a ‘0’ (=zero) if the candle is red (open > close); write a ‘2’ if the candle is a ‘doji’ (open = close).
    3. Save the price data of historic candles with the same codification (as above), i.e. the last 5.000 (will later be adjustable by user) candles into a second array.
    4. Compare the sample (step 1) with the historic data (step 3); if the pattern is found, then
    5. draw a second rectangle around the pattern within the historic data. And save the next 100 (also adjustable) candles following the found pattern into a third array.
    6. Project those candles into the future (after the current candle) so to speak.

    5a. if the pattern is not found, simply write a notification saying that into the chart. <- already working.

    I do have accomplished the steps 1 through 3.
    step 4 is not working yet. As I get confused with the way, PRC counts the candles.
    step 5 shouldn’t be a huge task to solve – similar to step 1.
    step 6 is already solved with your first response.

    Questions I still have:

    1. How does ProRealCode (ProBuilder) count the candles? I’m pretty sure, the current candle is counted as ‘0’ (=zero). But what about the prior candles? Will they be assigned any numbers from 1 to xyz counting upwards with each new candle forming?
    2. Why do I have to flip (reverse) the variable of the variable i (code line #32: idx = periodi    // reverse i to idx, 0-6 to  6-0)? Would I have to flip the indeces of the ‘historic array’ as well before any comparison with another array?

    I can provide my code if this would be helpful – as it has some lines (above 200) of now I would suggest to export it into a separate file instead of copy-pasting it. Any suggestions from the experts? 🙂

    Thanks again,
    Florian

    #234005

    Hi Florian, re: your questions…

    1. For a new bar to be valid, it has to have, at least one tick in the bars time period. A current count of the bars is stored in the variable ‘BARINDEX’. The first bar of a chart is barindex = 0, and is incremented by 1 every valid bar, and where the current candle is the highest value.

    Just to explain why I use the word ‘Valid’ for a bar,  if their is a bar time period, where there was no tick, then the barindex’s, current number, is not incremented. This could lead to the count of barindex, being different to the count of the time periods.

    You are right by saying the current candles index is [0] and, the previous one to that would be [1], and then [2], [3] etc. Now this is where it gets tricky. The current candle is always [0], so you can not directly look back to a specific candle as an index since it points to a different bar every new bar.

    If you compare the, barindex and the candle index, the barindex is increasing every bar and the candle index is also increasing but from the opposite end. This, because  the candle index shifts to the left by 1  bar on each new valid bar

    So the index is actually an offset from the current bar to a previous bar, where the current barindex is the reference point.

    Looking back to close[10] give the value of close 10 bar prior to the current barindex. After a new bar , then it still points to 10 bars ago but the reference point as change because barindex has been incremented by 1.

    Therefore to access the same candle, you need the barindex number, or the offset in bars since, for that candle, let say it was at  barindex 300, subtract that from the current barindex, lets say 550,  550-300 = 150, then the candle offset from current bar  = 150, close[150] or close[barindex-300].

    Now I think the draw command use the reference point from the other end, so you need the offset from barindex = 0,  to the bar you want, which I end up with  barindex[barindex- 300].

    2.  lines

    #4 candleNumber sets the number of candle required

    #8 period is set to 1 less than candleNumber, because array starts at index[0] ,  this aligns to give correct number required.

    #15-20  loads array ‘backward’ from current bar.

    # 26 creates a loop for the drawing of the candles in the future with the store array data

    # 28,29,30  ensures as ‘i’ increases the offset increase points to the next future bar, the +1 just set the start point to the first future bar when i=0.

    # 32   remember the data was stored backwards from the current bar in the array’s, but the future bars are being index forward, so the array needs accessing from last to first, which period – i  does.

    if i=0, then 0+1 points to first future bar, barindex+1,  if period = 9  {0 to 9}  then 9-0 = 9 for array index. Next time, when i=1, barindex + 2,  9-1  = 8, etc

    Regarding the rest i’ll look into it, posting code would be helpful, at least we would be on same page talking about same thing.

    I’m sure I have several questions, but  here’s the first,

    the first code I posted, made a patten using a number of bars, this pattern is going to change every new bar, is this what initiates the pattern or is it some other criteria.

     

     

     

     

    1 user thanked author for this post.
    #234012

     

    Q. what timeframe(s) are you planning on using?

    Looking through your specification:-

    1. Range,  between 3-7 max 10, that’s ok, but where does it start! Is it the last ‘closed’ candle, or the current. If current, then that candle will be always changing till it closes, changing the pattern till then, when it becomes the previous candle
    2. If bull/bear/doji value is assigned to variable “candle” on each bar, then these values are available using candle[n], just need to know the barindex of the start point, when searching. eg.  barindex – 5000
    3. As with 2. , no need to store historical candle’s price data since it’s already stored, just need to know the barindex or offset to the candle(s) required, then use close[n] etc.
    4. The code, should show a rectangle around the pattern, kind of, and at the bottom, the bull/bear/doji values of the pattern range and for all bars in the chart. Just need to compare using pattern code above.

    Q.  Is the pattern only matching the bull/bear/doji values 1,0,2  and the position sequence.

    Q.  Its possible that, there might be more than 1 match of the pattern, which one is going to be the relevant one for projecting forward.

    5.  A rectangle around found pattern, no problem, Again, no need to store 100 candle data, just need to know what barindex it starts, eg. current barindex  minus offset to start of pattern + pattern range + 1, retreve data using ohlc with [n].

    5a. No pattern label, no problem

    6.  Project 100 candles forward like in code above.

    once it’s up and running, the variable you want to adjust can be setup using the dynamic variable settings, may need to add limits to enter values and make sure they don’t break code.

     

     

    1 user thanked author for this post.
    #234240

    Hi Druby,

    first of all my apollogies for being offline the past week

    Secondly I want to thank you for all your support given so far. It was of great help and I hope that I can give it back one day. Currently I’m still learning a lot of how the ProBuilder works and how it doesn’t.
    However: with your great support and help I pretty much solved my initial challenges. But more are already on the horizon… So I’d kindly ask the admins of this forum to leave this post open for now.

    What you (and of course all other users of this forum) will find is the code of my indicator (defining it to be in some sort of alpha-status). It’s still under development and not 100% finished. Attached you’ll also find the export-file to use with your own ProRealTime Trading Plattform.

    *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
    Important Note:
    The use of this indicator is completely at YOUR OWN risk and does NOT recommend any trading ideas or decisions based on real money. I shall not be hold liable to any losses made due to using this indicator (Forecast_PRC_p-type).
    *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

    Attached you’ll also find a screenshot of the current state of my indicator. It shows the search pattern (rectangle with blue dashed line), the found pattern (rectangle thick green dashed line) and the result ‘vector’ (rectangle slim blue line). It also shows a potential output for the future price based on historic price information.

    So then – the code:
    I tried to structure it the best way possible and add comments to show what it does.

    Thank you and good trades.

    regards,
    Florian

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

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