Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom indicator

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

    Custom indicator

    Hello, how to create custom indicator HIGH - LOW, and find average value for n periods for this indicator?

    #2
    Hi U0000999, thanks for your question.

    The general logic in OnBarUpdate would go something like this:

    Code:
            int period = 20;
            protected override void OnBarUpdate()
            {
                if(CurrentBars[0] < period) return;
    
                double sum = 0;
    
                for(int i = 0; i < period; i++)
                {
                    sum += High[i] - Low[i] / 2;
                }
    
                Print(sum);
            }
    There are many different ways you can do this though. Take the SMA as a more complex example that sets up things that would be used on a regular basis like plots/inputs.

    Please let me know if I can assist any further.

    Comment


      #3
      Hi Chris,
      Congrats to your post no. 3000 :-) .

      I just added the average and some prints.

      int period = 20;
      protected override void OnBarUpdate()
      {
      if(CurrentBars[0] < period) return;

      double sum = 0;
      double average = 0;

      for(int i = 0; i < period; i++)
      {
      sum += High[i] - Low[i] / 2;
      average = sum / (i+1);
      }

      Print("Sum: " + sum.ToString("N2"));
      Print ("Period: " + period.ToString());
      Print("Average: " + average.ToString("N2"));
      }

      Thx.
      NT-Roland

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      22 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      24 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-25-2026, 09:53 PM
      0 responses
      30 views
      0 likes
      Last Post CaptainJack  
      Started by CaptainJack, 03-25-2026, 09:51 PM
      0 responses
      18 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 03-23-2026, 11:13 AM
      0 responses
      27 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X