Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unable to get indicators in strategy to propagate

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

    Unable to get indicators in strategy to propagate

    This is my code. It all compiles well. I just can't get anything other than the 5B0 to show up on the chart. It simply skips past it. It all compiles. I was reading it takes "Plots[1]" or something but I get compile errors or simply an inability to start my strategy when I use "1" or "2". I'm sure it's something super simple. I'm just missing it.

    Code:
    else if (State == State.DataLoaded)
    {
    Print($"BarsArray Length: {BarsArray.Length}");
    for (int i = 0; i < BarsArray.Length; i++)
    {
    Print($"BarsArray[{i}] is {(BarsArray[i] != null ? "valid" : "null")}");
    }
    
    
    // Instantiate indicators
    sma5B0 = SMA(5);
    sma50B0 = SMA(50);
    sma5B1 = SMA(BarsArray[1], 5);
    sma50B1 = SMA(BarsArray[1], 50);
    sma5B2 = SMA(BarsArray[2], 5);
    sma50B2 = SMA(BarsArray[2], 50);
    
    // Add indicators to the chart
    AddChartIndicator(sma5B0);
    AddChartIndicator(sma50B0);
    AddChartIndicator(sma5B1);
    AddChartIndicator(sma50B1);
    AddChartIndicator(sma5B2);
    AddChartIndicator(sma50B2);
    
    // Add indicators to the chart with specified colors
    sma5B0.Plots[0].Brush = Brushes.GreenYellow;
    sma50B0.Plots[0].Brush = Brushes.Green;
    sma5B1.Plots[0].Brush = Brushes.Yellow;
    sma50B1.Plots[0].Brush = Brushes.Goldenrod;
    sma5B2.Plots[0].Brush = Brushes.Orange;
    sma50B2.Plots[0].Brush = Brushes.Red;
    
    Print("Indicators Colored");
    
    }
    }​
    Last edited by alphatango; 01-15-2025, 05:59 PM.

    #2
    Hello alphatango,

    Thank you for your post.

    Indicators added via AddChartIndicator will only use the primary data series, they cannot use any additional data series. This is noted in the Help Guide page for AddChartIndicator:

    "An indicator being added via AddChartIndicator() cannot use any additional data series hosted by the calling strategy, but can only use the strategy's primary data series. If you wish to use a different data series for the indicator's input, you can add the series in the indicator itself and explicitly reference it in the indicator code (please make sure though the hosting strategy has the same AddDataSeries() call included as well)​"

    Comment


      #3
      Hi Gaby,

      I did add this
      Code:
      else if (State == State.Configure)
                  {
                      // Add a 5-minute Bars object to the strategy
                      AddDataSeries(Data.BarsPeriodType.Minute, 5);
                                      
                      // Add a 15-minute Bars object to the strategy
                      AddDataSeries(Data.BarsPeriodType.Minute, 15);
                      
                  }​
      I wasn't totally sure how to get it into the information, so I used some chatgpt. If there's some syntax problems, let me know.

      Comment


        #4
        Hello alphatango,

        The issue isn't the added data series, these can be added to the script. The issue is that added data series can't be used by indicators using AddChartIndicator.

        You would need to go into the indicator's code and create a version that explicitly already (references) runs on the desired data series.

        Comment


          #5


          What's odd is that I see that it will propagate ​the other timeframes, but only in the first 10% of the data loaded. If I load 30 days, it will cease after a certain bit. Oddly, the Red/Orange In the top of this picture is the higher timeframe and it stops very quickly. The Orange/Yellow is the next timeframe, and it seems to last about twice as long. So it's loading, but I'm very concerned with the numbers its giving me and the fact that it's cutting out. Is my algorithm processing properly? In theory the 1m (the squeeze in the middle) and the Orange/Yellow (5minute) should be closer together, right? I can't seem to tell if that's accurate for the data I'm requesting.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          63 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          139 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          75 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          50 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X