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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      54 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      72 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      38 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      99 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      60 views
      0 likes
      Last Post PaulMohn  
      Working...
      X