Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    JesseNinjaTrader Customer Service

    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 f.saeidi, Today, 12:14 PM
      7 responses
      16 views
      0 likes
      Last Post f.saeidi  
      Started by Russ Moreland, Today, 12:54 PM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by philmg, Today, 12:55 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_ChristopherJ  
      Started by TradeForge, 04-19-2024, 02:09 AM
      2 responses
      32 views
      0 likes
      Last Post TradeForge  
      Started by aprilfool, 12-03-2022, 03:01 PM
      3 responses
      329 views
      0 likes
      Last Post NinjaTrader_Adrian  
      Working...
      X