How to use get set accessor with a list?

FranK Duc 121 Reputation points
2021-07-13T14:22:16.067+00:00

Hello,

I am trying to use the result of my list in another class.

 public class NEWSDBA : Indicator
    {
//should i declare private my listm here??

protected override void OnBarUpdate()
        {

             foreach (var item in listm)
 {
 //use the values inside the listm declared in 
                                       //protected override void OnRender
 }
        }


protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {

var listm = new List<double>();

// use values of listm in protected override void OnBarUpdate()


        }

}
Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. FranK Duc 121 Reputation points
    2021-07-14T15:05:57.89+00:00

    Timon,

    The code is too long. What i can say is if i declare or initialize listm private it will return a different answer.

    protected override void OnBarUpdate() and protected override void OnRender are classes coming from the software ninjatrader, charting software.

    I want to use AddPlot method to create a line in the chart from the values in listm but AddPlot method will only work in OnBarUpdate().

    According to the tech at NT :

    A value would need to be assigned to the plot in OnBarUpdate(), then you would call base.OnRender() in OnRender() to ensure Plots are rendered along with custom render logic.

    protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description = @"new version of SDBA";
                    Name = "NEWSDBA";
                    Calculate = Calculate.OnEachTick;
                    IsOverlay = true;
                    DisplayInDataBox = true;
                    DrawOnPricePanel = true;
                    DrawHorizontalGridLines = true;
                    DrawVerticalGridLines = true;
                    PaintPriceMarkers = true;
                    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive = true;
                    TBPrice                                     = 0;
                    CheckV                                      = true;
                    Volume                                      = 0;
                    AddPlot(Brushes.Yellow, "NEWSDBA");
    
                }
            }
    
            protected override void OnBarUpdate()
            {
    
    
    
            }
    
    
    
    
            protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
            {
    
    
    
                //CMA minute
                var lists = new List<double>();
                var listv = new List<double>();
                double avg = 0;
                double closePrice = 0;
                double volumes = 0;
                double sum1 = 0;
                double sum2 = 0;
            double fibo2 = 0;
    
    
                for (int barIndex = foundIndex; barIndex <= ChartBars.ToIndex; barIndex++)
                {                
                    closePrice = Bars.GetClose(barIndex);
                    volumes = Bars.GetVolume(barIndex);
    
                    if (CheckV)
                    {
                    avg = Volume;
                    }
                    else 
                    {
                    avg = sum2 / RfoundI;
                    }
    
    
    
                    double clovol = closePrice * volumes;
    
    
                    sum1 += clovol;
                    sum2 += volumes;
    
                    cma = sum1 / sum2;
    
    
            lists.Add(closePrice);
                    listv.Add(volumes);
    
                }
    
    
    
    
    
    
                var listm = new List<double>();
                listm.Add(Close.GetValueAt(CurrentBar));
    
    }
    }
    

    If you can make sense of this be my guess.

    Thank you


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.