Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    JesseNinjaTrader Customer Service

    Comment


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

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Johnny Santiago, 10-11-2019, 09:21 AM
      95 responses
      6,193 views
      0 likes
      Last Post xiinteractive  
      Started by xiinteractive, 04-09-2024, 08:08 AM
      2 responses
      11 views
      0 likes
      Last Post xiinteractive  
      Started by Irukandji, Today, 09:34 AM
      1 response
      3 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by RubenCazorla, Today, 09:07 AM
      1 response
      5 views
      0 likes
      Last Post RubenCazorla  
      Started by TraderBCL, Today, 04:38 AM
      3 responses
      25 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X