How to test if we are on the latest bar ?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #113316 quote
    bobt
    Participant
    Average

    Hi,

    I am writing an indicator where sometimes I want to calculate against all bars, and sometimes only against the most recent bar.

    Effectively I want to be able to use “DEFPARAM CalculateOnLastBarOnly” but within an IF statement driven by a boolean variable declared against the indicator ( thereby allowing a user to control the output ).

    However, from what I can see the DEFPARAM can’t be placed within an IF, and so I need to code this for myself.

     

    How do I detect ( elegantly !! ), if I am currently working against the “current” candle ?

    This indicator can be used against ANY timeframe, and so comparisons against currenttime become quite messy, quite quickly.

    BarIndex effectively numbers from the beginning of the available bars – I need the inverse of BarIndex, so that I’m at 0 when on the current bar.

     

    Does anyone have any elegant solutions ?

     

    Regards,

     

    Bob

    #113317 quote
    Nicolas
    Keymaster
    Master

    With the use of the new available instruction (only in version 11) : IsLastBarUpdate

    #113318 quote
    bobt
    Participant
    Average

    Hi Nicolas,

     

    Thanks for the quick reply – it’s good to know there is now a built in way of achieving this ( is full documentation of the new v11 commands available as yet ? ).

     

    However, my users are mainly customers of IG, who have not rolled out v11 yet, and so I still need to achieve this the “old fashioned” way .. 🙁

     

    If anyone has any good ideas, I’d be very grateful.

     

    Regards,

    Bob

    #113400 quote
    Nicolas
    Keymaster
    Master

    The old way was by using this kind of condition:

    IsLastBarOnChart=currenttime=opentime and date=today

     

     

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

How to test if we are on the latest bar ?


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
bobt @bobt Participant
Summary

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

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 11/21/2019
Status: Active
Attachments: No files
Logo Logo
Loading...