Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get value from a chart and then pass it to another

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

    Get value from a chart and then pass it to another

    Hello Support,

    I need to understand a question.
    If I need to have an indicator that prints the highest high of an instrument (absolute max since that instrument exist) I can do it loading the number of bar in that chart till that max.

    For example:
    If I try to print the absolute max of Nasdaq in a 10 range bar chart, I need to load about 2 years of data (over 3.000.000 of bars...)
    In this case my indicator work well but my computer go in crash often (this is not the only calculation that I need to do)

    Is there a way to get the max from a daily chart (about 750 bars) and then pass the value to my indicator on 10 range bar?

    So I need to load only 750 bars in the daily chart, and few days in the 10 range bars.
    This will be better from my pc resource.

    Can you help me ?

    thank you
    best regards

    Andrea

    #2
    Hello AndreaBhs,

    Yes you can do that by using AddDataSeries with its bars to load overload set:

    AddDataSeries(null, new BarsPeriod() { BarsPeriodType = BarsPeriodType.Day, Value = 1}, 30, null, true);



    This would assume the primary instrument and add 1 day bars. This adds 30 bars, you could replace the 30 with however many day bars are needed.

    Once you load that series you can use any of the indicators like MAX or use methods like HighestBar on that series.

    Code:
    double value = MAX(BarsArray[1], 750)[0];
    ​
    int highestBarsAgo = HighestBar(BarsArray[1], 750);





    Comment


      #3
      Hello Jesse,
      thank you very much, this is exactly what i was looking for!
      I didn't know about "barsToLoad" method!

      I just tried and with MAX function I get the close of the daily previous bar instead of high.
      So, with BarsArray I get Close value, with HighestBar I get an error about index invalid since out of range.

      Follow my Code:
      Code:
      if (State == State.Configure)
      {
      AddDataSeries(null, new BarsPeriod() { BarsPeriodType = BarsPeriodType.Day, Value = 1}, 300, null, true);
      }​
      
      protected override void OnBarUpdate()
      {
      if (CurrentBar < 1 || BarsInProgress == 1)
      return;
      
      if (BarsInProgress == 0)
      {
      int i = HighestBar(Highs[1], 300);
      Print(Time[i] + ": " + Highs[1][i]);
      }
      
      // int i = HighestBar(BarsArray[1], 300);
      // Print(Time[i] + ": " + High[i]);
      
      
      // double value = MAX(BarsArray[1], 300)[0];
      // Print(value);
      
      
      ​}

      Comment


        #4
        Hello AndreaBhs,

        I believe that the time you are using, you are passing the number of daily bars ago to the primary series time. Try the following instead:

        Code:
        protected override void OnBarUpdate()
        {
            if (BarsInProgress == 1)
              return;
        
           int i = HighestBar(Highs[1], 300);
           Print(Times[1][i] + ": " + Highs[1][i]);
        }

        Comment


          #5
          Thanks for support Jesse, but I still get the same error:

          Error on calling 'OnBarUpdate' method on bar 1: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
          I modified time as you told me:

          Code:
          if (CurrentBar < 1 || BarsInProgress == 1)
          return;
          
          if (BarsInProgress == 0)
          {
          Print("65");
          int i = HighestBar(Highs[1], 300);
          Print("67");
          Print(Times[1][i] + ": " + Highs[1][i]);
          }
          Print("65") work ok, Print("67") doesn't work, so I think the problem is in the following line
          Code:
          int i = HighestBar(Highs[1], 300);

          Comment


            #6
            Hello AndreaBhs,

            I am not certain what the problem is, have you opened a daily chart and made sure you have 300 days of data loaded?

            I tried the following and see prints:

            Code:
            protected override void OnStateChange()
                    {
                        if (State == State.SetDefaults)
                        {
                            Name                                        = "ATest";
                            Calculate                                    = Calculate.OnBarClose;
                        }
                        else if (State == State.Configure)
                        {
                            AddDataSeries(null, new BarsPeriod() { BarsPeriodType = BarsPeriodType.Day, Value = 1}, 300, "", true);
                        } 
                    }
            
                    protected override void OnBarUpdate()
                    {
                        if (BarsInProgress == 1)
                            return;
            
                        int i = HighestBar(Highs[1], 300);
                        Print(Times[1][i] + ": " + Highs[1][i]);            
                    }
            1/4/2022 3:00:00 PM: 4853

            Comment


              #7
              Hello Jesse,

              Yes, I can see more of 300 days of data.
              I noted that if I load more then 300 bars, for example 350, and then I search highest for only 300 bars indicator work well.
              If I load 300 bars and search for 300 bars i get the error

              Comment


                #8
                Hello AndreaBhs,

                You may need to specify more than 300 to account for holidays or missing days. I loaded the ES instrument in my test.

                The index error can be solved by using a condition like the following however that would likely prevent the print if you are using less than enough data.

                Code:
                protected override void OnBarUpdate()
                {
                    if (BarsInProgress == 1)
                     return;
                    if(CurrentBars[1] < 300)
                     return; 
                
                    int i = HighestBar(Highs[1], 300);
                    Print(Times[1][i] + ": " + Highs[1][i]);
                }

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                637 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                366 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                107 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                569 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                571 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X