Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Finding the maximum of a variable within a bar

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Finding the maximum of a variable within a bar

    Hi,

    I am trying to find the maximum of a variable inside a single bar. For example, I would like to know what the maximum delta during a volumetric bar is. It sounds like an easy task, but I cannot get it working. I use a logic like this:


    protected override void OnBarUpdate()
    {
    int paraMax;

    if(IsFirstTickOfBar)
    {
    paraMax = 0;
    }

    f = f is a function that changes during a bar, e.g., delta

    paraMax = Math.Max(paraMax, f)

    Draw.Text(this , "MaxDelta" ,paraMax , 0, Low[0]-2*TickSize);
    }


    I think the problem is how to define and initialize a variable only at the beginning of a bar. I appreciate any help.




    Last edited by Photon66; 12-01-2020, 09:50 AM.

    #2
    Hello Photon66,

    Thank you for the post.

    Yes this is likely that you are creating the variable on each tick, you would need to move the variable definition outside the OnBarUpdate method:

    Code:
    private int paraMax;
    protected override void OnBarUpdate()
    {
    That would make it an always the same value across all bars unless you change it. Then on each tick it will check the max and the existing value, on each first tick of the bar it would then reset.

    I look forward to being of further assistance.

    Comment


      #3
      Thank you very much, Jesse. Your suggestion worked.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      648 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      369 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      572 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      573 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X