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 NullPointStrategies, Today, 05:17 AM
      0 responses
      44 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      124 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      65 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      42 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X