Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

access to variables from indicator in strategy

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

    access to variables from indicator in strategy

    Hello , I only get a zero value from the variable, why? As an example I use the SampleBoolSeries.cs and MyCustomIndicator.cs

    SampleBoolSeries
    Code:
    public class SampleBoolSeries : Indicator
    {
       private double exposedVariable;
    
       protected override void OnBarUpdate()
       {
         exposedVariable = Close[0]; Print(ExposedVariable);
       }
    
       public double ExposedVariable
       {
         get { Update(); return exposedVariable; }
       }
    MyCustomIndicator
    Code:
    public class MyCustomIndicator : Indicator
    {
       SampleBoolSeries boolSeries = new SampleBoolSeries();
    
       protected override void OnBarUpdate()
       {
         Print(boolSeries.ExposedVariable);
       }
    }
    the goal is to make calculations in a file (indicator.cs) and then use them in a separate file (strategy.cs)
    I don't understand why a 0 appears, t​​​he access to the variable should be set right. can someone please give me a tip, that would be great


    Click image for larger version  Name:	Screenshot_3.jpg Views:	0 Size:	239.2 KB ID:	1122802Click image for larger version  Name:	Screenshot_4.jpg Views:	0 Size:	134.6 KB ID:	1122803




    Last edited by sidlercom80; 10-15-2020, 05:51 AM.
    sidlercom80
    NinjaTrader Ecosystem Vendor - Sidi Trading

    #2
    Hello sidlercom80,

    One problem here is that you never actually call the indicator to have it process, you only try and access the property. The property is only going to be set if OnBarUpdate processes.

    Generally you will need to either access a Plot or Series like shown in the sample in addition to the public property. You can also try using Update from the strategy like the following:

    Code:
    protected override void OnBarUpdate()
    {
    boolSeries.Uppdate();
    Print(boolSeries.ExposedVariable);
    }
    If the indicator will have any plots you should avoid calling update and just call one of the plots:

    Code:
    double dummyValue = boolSeries.MyPlot[0];
    If you are not able to see the script working, could you attach the strategy and indicator test so I can run what you have?

    I look forward to being of further assistance.

    Comment


      #3
      Hi _Jesse thank you very much for your answer, it helped me
      sidlercom80
      NinjaTrader Ecosystem Vendor - Sidi Trading

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      47 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      23 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      33 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      51 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Working...
      X