Arrays & Same Candle Programming

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #232352 quote
    IG_CFD_Trader
    Participant
    Average

    Hi All,

    I though I would ask one last time if the below is possible in current version of ProBuilder.

    If IsLastBarUpdate is true then

    1. store price and say average[20] value of current candle in an array variable.

    Then when IsLastBarUpdate is true again then

    1. there is nothing to compare since array above only has 1 price and 1 average[20] value
    2. just store the second reading of price and second reading of average[20] value in the same array above

    Then when IsLastBarUpdate is true again then

    1. Check price against the prices stored in array above
    2. if there is a match then compare the average[20] value of this reading with the average[20] value of the matched price in the array then continue storing the two new values in the array
    3. If there is not a price match, then just store the values in the array as usual.

    Continue doing the above whilst IsLastUpdate continues to be true until close of the current Bar.

    Can current version of Probuilder handle the above or not yet?

    Many thanks

    #232444 quote
    druby
    Participant
    New

    hi… see if this is getting anywhere!

    druby

     

    // !!! default timeframe 1 minute
    
    
    timeframe(20minute, updateonclose)  // update only every 20 minutes
    close20m = close                    // 20minute close
    barIndex20m = barindex              // 20minute barindex
    
    
    timeframe(1minute )                 // 1minute timeframe
    close1m = close                     // 1minute close
    
    
    if barIndex20m <> barIndex20m[1]then           // end of 20minute bar!
    drawvline(barindex[20])style(dottedline,1)  // denote with vertical line
    
    // calculate the 20minute bar average based on last 20 1minute bars
    avg1m = average[20](close1m)   
    // display this average over the relative 15minute bar width            
    drawsegment(barindex,avg1m,barindex[20],avg1m)style(dottedline,2)coloured("blue")
    
    // table variables
    print(close20m[1]) //  this [1] aligns up  20m close with the avg1m value
    print(avg1m)       //  in table 
    print(barindex20m)
    endif
    
    return close20m coloured("red")as"20m Close",close1m coloured("lime")as"1m close"
    #232481 quote
    robertogozzi
    Moderator
    Master

    Can you make an example with some data?

    In addition, what would you like to do with the array containing those data?

    #232504 quote
    IG_CFD_Trader
    Participant
    Average

    Hi Roberto,

    Drubi did a good job above but unfortunately he had to use multi timeframes strategy (like a trick) which gives rise to two issues:

    1. I have to apply the code to the lower timeframe which is a multiple of the higher timeframe
    2. Perhaps Prorealcode is not ready yet or cannot handle capturing data from a current Bar directly on any timeframe once chooses.

    I will try to re-explain with an example as you asked:

    • Assume I am looking at a 1 hr time frame.
    • I have a current Bar obviously with price (close) moving up and down during market session (or assume after 10am i.e. after market open)
    • Assume also I have an indicator running (RSI, MACD, VWAP, etc…) which also registers a reading every time the current bar price moves up and down

    Now given the above:

    • Can prorealcode use an expression like (if islastbarupdate then) or any other expression for that matter to
      • Capture both the price and the indicator reading value and store them as fixed values somewhere for later use?
      • Capture the next price and indicator reading everytime the bar updates and store them next to the first readings above
      • Keep on capturing and storing price and indicator readings for as long as the current bar is updating?
      • The above has to be done directly to the current bar on the one timeframe itself without the need to resort to a lower timeframe as a trick to get around the issue

    Whilst the code is continually storing, I just want to for example Print the data and maybe print or display the cumsum or summation of the data from open time of the Bar (say 10am) etc which should not be hard to do. The hard part is the live continual capture and storing of the data as I described above.

    Tnx

    #232517 quote
    pableitor
    Participant
    Master

    I tried to do like you said but AFAIK theres no way to store tick data in any array or variables, much less use them to trade in higher timeframes. You just can  view it if you previously declare <defparam drawonlastbaronly = true>

    Please someone correct me if I am wrong.

    Iván González thanked this post
    #259833 quote
    IG_CFD_Trader
    Participant
    Average

    Back to this topic fellows. Can Probuilder/Prorealtime detect and interpret indicator logic within current candle or still only when candle closes and past candles?

    #259849 quote
    robertogozzi
    Moderator
    Master

    While strategies are only run when a candle closes, Indicators (and Screeners, as well) run live and update their output every new incoming tick (or just a few ticks).

    If you sit your mouse ON a candlestick (provided the info about it are enabled, which should be by default), especially on a low timeframe, you will see data changing quite often.


    #259850 quote
    PeterSt
    Participant
    Master

    Don’t laugh …

    I saw the original date of this topic and thought : wait, I think it was so that I found a way after all and this must have been *after* the date of this topic (May 24). Not being sure about that, I googled for it in order to find back that particular discussion. Ready for the laugh ?


    AI-overzicht


    In ProRealTime (PRT), specifically within ProRealCode forums, PeterSt is a prominent user who has extensively discussed, tested, and sometimes challenged the limitations of array variables and tick-level data, particularly in the context of ProOrder automated trading strategies. 

     +2

    Array Variables and Tick Data according to PeterSt’s discussions:

    • Tick-by-Tick Data Challenges: PeterSt has noted that while tick-by-tick data is crucial for strategies, backtesting with it can be inconsistent, and it is sometimes tricky to properly leverage within the strategy code.
    • Arrays within Strategies: Arrays (variables denoted with $) can be used to store data over time or within bars. PeterSt and others in the community have clarified that arrays can persist across bars, contrary to early understandings, allowing for the storage and computation of historical data points.
    • Data Access Limitations: A key topic in PeterSt’s discussions is that while you might be able to print or graph tick data within an indicator, storing that specific, highly granular tick data within an automated strategy (ProOrder) is not always possible.
    • Alternative Approaches: PeterSt often engages with other users (like Nickolas and Roberto) to find workarounds, such as using ONCE to declare array variables to ensure they are properly initialized before use. 
    •  +3



    ————————–

    And this with the notice that I left the working out to the community here and never heard back about it. Btw, this surely was not about engaging different time frames. Anyway :

    So Yes, within Indicator logic, array elements can be filled with “bar data” from within that Indicator code. The array elements sustain, contrary to any normal variable.

    The programming within this “logic” will at least be buggy or hard to debug and analyze, because nothing is really made for it. Also, the working with arrays themselves within PRT I deem a sheer pain (this is personal), which does not help in attempting these things for real myself. And oh, @druby is surely often/always involved himself in these matters (arrays) but I think that in the end nobody really grabs the real merit of it all – it is and remains unofficial that this can work. Please note : most of the attempts end up in not understanding because it is very hard to see through what internally happens.


    Important

    What I did try once was at the rough level trying to incorporate this “array behavior within bars” (like storing tick data) from within Strategy Code and then by means of calling Indicator code. This plainly can not work because Strategy code is meant for Backtesting (and Optimizing) and in the end ProOrder; in that environment no tick data is processed anywhere, thus also not in Indicator code. Indicators are for the graphical environment (!). Additionally, while Indicators can return a value when called from Strategy Code which would really work within ProOrder as well (we all know that) it is still so that whatever the indicator is, it won’t work with tick data. On-screen (graphically) Yes, and within that environment Array elements can be written by the tick. And so … this could be useful for manual trading and literal “indicator” stuff, it is useless when ran on PRT’s servers (outside of the graphical environment).


    That an indicator (code) can also be used as a sub routine, is something unrelated. Read : The existence of calling an indicator from within Strategy Code is fully justified. But for way different objectives.


    Last word : in an example somewhere, related to the new ProRealCode forum/community environment, Nicolas kind of in between the lines told that Indicators nicely could be used as subroutines (these days), which he also excessively used in his examples. He hinted / implied that there was no necessity to wait for the due real sub routines because the indicators can do all. Well, I can fully subscribe that. And for example, these days they are not a bit slower then de sub routine code being in the main program code itself.

    But … force that by trickery into using tick data after all, and you will get no response from the Strategy Code any more. I don’t think it is possible, but would it be, then know that Nasdaq presents over 10K ticks per second once the market is open (IG could even be more). And no way that will work on the PRT servers. On your own with a really fast PC this is already cumbersome – and there you are the only user.



    Curious what AI will make of this post. Haha.

    Peter

    #259851 quote
    GraHal
    Participant
    Master

    Well I’ve seen / heard it all now … ask AI a question and get yourself quoted back as the answer! HAHAHAHA

    Nice One Peter 😀

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

Arrays & Same Candle Programming


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
IG_CFD_Trader @wnakhoul Participant
Summary

This topic contains 8 replies,
has 6 voices, and was last updated by GraHal
2 weeks, 2 days ago.

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