Any way to plot a time based moving average over a tick chart ?

Forums ProRealTime English forum ProBuilder support Any way to plot a time based moving average over a tick chart ?

Viewing 8 posts - 1 through 8 (of 8 total)
  • #230534

    Hi everyone,

    I was wondering if there is any simple way to plot a time based indicator over a tick chart.

    For example, normally if I plot a 100 period SMA (simple moving average) on a tick chart, it will obviously average the last 100 ticks, for each tick.

    I would like to be able to plot, for example, a 10 minutes period SMA over a tick chart, this means the SMA will average the last X ticks that were generated during the 10 last minutes, for each ticks.

    Maybe using arrays it could be feasible though I’m not sure how to implement it yet.

    (Also maybe there are native methods in ProRealtime that would allow to do that and I am not aware of it )

    Thank you very much !

    #230569

    No, different kinds of timeframes cannot  be mixed, such as time-based and ticks.

    You can only use MTF with the same type. You may use a default 10-tick TF to plot a 100-tick SMA as their types match.

     

    #230589

    No, different kinds of timeframes cannot  be mixed, such as time-based and ticks.

    You can only use MTF with the same type. You may use a default 10-tick TF to plot a 100-tick SMA as their types match.

    I see, it is a pity as it is a feature available on some other platforms.

    So, the only way would be to store tick close in an array and corresponding time in a different array, with same indexes, and then loop through it to calculate the averages..

    Or does anyone thinks there can be a simpler way ?

    Thank you.

    #230600

    Hello 0309 san !

    I think your idea is good. But I would attempt it without arrays. In any event, please keep in mind that you won’t be able to AutoTrade with this. In other words : AutoTrading will require a normal TimeFrame and although you can show tick data in an indicator, you won’t be able to store that data and use it. At least that is what I think.
    But for normal visualization of what you ask, this could be the pseudo code, not using arrays :

    I hope you get the idea ?

    Do keep in mind that the code will be called only when a tick (a trade) occurred. So it will need extra attention to properly calculate the average within the time periods; No ticks during the YourTimeBar periods may imply a gap of several (virtual time) bars and the average should stay in-tact. The price won’t be zero during that time, but merely the same as the last one used in your previous average calculation.


    I would imagine that others have done such a thing before; hopefully they read this and provide some ready code for you. It won’t be really easy to create, I think.

    Regards,
    Peter

    #230620

    Thank you very much for taking the time to reply.

    Yes, I just need it as a visual indicator, I won’t use AutoTrade or anything automatic.

    I managed to get somehow desired result using arrays, but because of the looping the loading is a bit slow, and if I want to use several averages on same chart, it might be too heavy.

    I am sorry but I am not sure I understand the logic in the “reasoning code” you suggested me, if you may be able to explain it differently ? As it might indeed be less heavy for calculation.

    For the info, I want to use it on 1 tick chart, so I wont use it on 100 ticks candles charts for example. 1 tick = 1 bar

    Thank you for your help !

    #230621

    Each bar your program is called. So in your case, each tick the program is called.
    At each call you must determine whether the time period of your (virtual) time bar has changed. Take one minute for each thinking. So each call you determine

    So you are building up the average in real time.
    You can of course start with a 1 minute TF chart and do exactly the same, and compare with a normal Average function from PRT to see whether you do it correctly. If it works, then you can change the chart to the TF of 1 Tick and see whether it still works. If not, you should be able to see relatively to the working situation what to change.

    Your prospect is that it will be fast as lightning.


    You could consider why you actually want to start off with a 1 tick chart. Thus, why not 1 second, for example ? Then you would have no problems at all.
    Thinking twice myself, I am not really able to envision how your 1 tick chart will look like when a time-period average would show; it would need to stretch the ticks into a time domain and that is not even possible. Anyway, you say you already have something which works. I am curious how that looks like ?

    #230623

    Thank you again for your reply.

    So, maybe it seems there is a misunderstanding, or I am not understanding what you mean.

    At each call you must determine whether the time period of your (virtual) time bar has changed.

    I would have the impression that the virtual time bar changes on every tick ? It might be because I am not too used to prorealtime coding yet but I don’t understand on the logic you gave me, how it is able to calculate the number of ticks necessary to get the desired average.

    For example, if I want to plot a 30min average on my tick chart, the average of X ticks that occurred during the last 30 minutes is calculated, every new ticks. Sometimes it will be the average of the last 2000 ticks, sometimes 1000.

    To be sure we are on the same reasoning :      if on the last tick the timestamp was 14h:05min:35sec , I will need to calculate how many ticks there were between 13h:35min:36sec and 14h:05min:35sec, and then average their close.

    You can see on my screenshot in attachment an example of the 30 min average on the tick chart. The bottom indicator is to show the number of ticks that occurred during the last 30 minutes, which changes more or less every tick.

    Anyway, you say you already have something which works. I am curious how that looks like ?

     

    #230986

    I would like to be able to plot, for example, a 10 minutes period SMA over a tick chart, this means the SMA will average the last X ticks that were generated during the 10 last minutes, for each ticks.

     

    Hi,

    if I understand correctly your request and subsequent posts, I would respectfully disagree with your assessment to average last X ticks that were generated during the 10 last minutes.

    What your classic 10mn timeframe SMA with period N is made of, is :

    • if for a candle in the past: the sum of latest N 10mn close divided by N. It would therefore look like stairway flat steps with vertical height change at beginning of each new 10mn slot, although arguably assigning to a 10mn slice the value of such step only reached at the end would be some kind of minor repainting (using a future value not known yet in real time to draw a past situation). To avoid repainting it could be plotted « one step late », by this I mean when the close of 10mn is known, draw the SMA value reached as a flat step on the « next » 10mn slice, but graphically not pleasant and not fun for live
    • if for a live candle: ( the sum of latest N-1 10mn close + current price ) divided by N. Such latest step wouldn’t be fully flat then, it would be variable until the last tick of the 10mn slot, kept as representative of those 10mn, and a vertical shift occurs at next live first tick of the newest 10mn slot

     

    What you can do, and still call it a classic 10mn timeframe plotted over a tick by tick chart, is to emulate in the past what would have been the live behaviour of the 10mn SMA at each tick. This doesn’t repaint anything, and it is not one 10mn slice late either, as the last tick of each 10mn slot is the final representative of its 10mn in the SMA, and all ticks prior to it in same 10mn slice lead to the “temporary” value the SMA would have had live at such intermediate tick.

    If such « stairs with non-flat steps » look is what you want, then the following code for TF10mn should do it, you can customise the period of the SMA with variable N (here N=50 just as an example), and the bigger the N you choose, the more you need to make sure you have loaded enough history to be able to start displaying the SmaN on your tick by tick chart:

     

    Don’t get me wrong, you are of course very free to want each 10mn be represented in the tick by tick chart by the average of all ticks for each 10mn instead of its 10mn close (a little bit like when choosing medianprice or totalprice instead of close)… then it would be coded differently, and be named differently than “a classic 10mn timeframe SMA” because it would never have a classic timeframe 10mn chart equivalent as such chart only has 10mn OHLC data in its history -Open High Low Close- , not the past ticks inside history candles (would only have the live ticks occuring post-launch of indicator).

     

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

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