Total number of bars

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #67049 quote
    Michael BazzantiMichael Bazzanti
    Participant
    New
    Hi guys, I made an indicator with Centered Mobile Averages and to translate the data I have to know how many bars are on the graph, and I use: return barindex just know the exact number (it changes on different graphs) Is there anyway to solve this? Thanks
    #67154 quote
    NicolasNicolas
    Keymaster
    Legend

    >> Please update your country flag in your profile. Thank you šŸ™‚ <<

    BARINDEX will always return the bars quantity of the opened chart. So sorry if I don’t understand but what do you want to do exactly please? Because if you use BARINDEX as your period for your moving average, it will instantly calculate the good mean for all the data displayed on your chart.
    #67159 quote
    Michael BazzantiMichael Bazzanti
    Participant
    New
    Usually i read the number of total bars and then write it on my indicator as a parameter (see image). If I use barindex as a variable inside the code it doesn’t work because it has a different number for every bar, but I want just the last one.
    REM traslazione
    
    if (barindex <= numbars - indietro) and (barindex > indietro) then   //numbars = total number of bars seen from barindex
    if indietro = 0 then
    ind = close
    elsif indietro = 1 then
    ind = -DPO[1](close)+close
    elsif indietro = 2 then
    ind = 2*(-DPO[2](close)+close) - (-DPO[1](close)+close)
    else
    ind = (2*indietro-2)*(-DPO[2*indietro-2](close)+close) - (2*indietro-4)*(-DPO[2*indietro-4](close)+close)-close[indietro-3]
    endif
    //ind1 = round(ind)
    ind1=ind
    else
    if barindex<= indietro then
    ind1 = undefined
    else
    ind1 =ind1[1]
    endif
    endif
    
    return ind1 as "traslazione"
    
    Schizzo.png Schizzo.png
    #67197 quote
    NicolasNicolas
    Keymaster
    Legend
    To know if you are on the last bar of the chart, you can use the code snippet below:
    LastBarOnChart=currenttime=opentime and date=today
    return LastBarOnChart
    But because the history is only read once, in your case, you will not be able to use it as a period for your indicator automatically. Another way would be to make loop in the past starting only on the current bar and with the last barindex as the period.. But still, ProBuilder doesn’t allow to plot curves in the past..
    robertogozzi and Michael Bazzanti thanked this post
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTimeā„¢ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Total number of bars


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by NicolasNicolas
8 years, 6 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 04/03/2018
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...