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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      82 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      43 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      64 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      68 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      56 views
      0 likes
      Last Post CarlTrading  
      Working...
      X