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

Indicator.IsCreatedByStrategy

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

    Indicator.IsCreatedByStrategy

    I would like to know if an indicator is being called from within a strategy or not but it doesn't seem to be working.


    From within the indicator I am checking like so below and it prints when I add the indicator to the chart independently but doesn't recognize when added via a Strategy.

    from within a Strategy within State. Dataloaded

    Code:
    if(this.IsCreatedByStrategy)
    Print("Created by strategy");
    else
    Print("Independently added");
    I also tried from within the Strategy within State. Dataloaded and it also doesn't recognize that it was loaded by a strategy

    AddChartIndicator(indi);
    if(indi.IsCreatedByStrategy)
    Print("indi Created by strategy");
    else
    Print("indi NOT Created by by strategy");

    #2
    You might try:

    Print (Parent.GetType()) to find out the caller. then you can compare : `if (Parent == Strategy...)`

    I have been searching a lot for this in the past, and this was my solution for similar cases.
    Last edited by ttodua; 10-15-2020, 02:41 PM.

    Comment


      #3
      Hello cutzpr, thanks for your post.

      IsCreatedByStrategy is not documented, so there is no guarantee it will work or was meant to be used in NinjaScript. How is the indicator being used in the strategy? You can make the indicator call Update() to force its OnBarUpdate function to be called e.g. from the strategies OnBarUpdate:

      Code:
      private TestIndicator TI;
      ...
      else if (State == State.DataLoaded)
      {
      TI = TestIndicator();
      }
      ...
      protected override void OnBarUpdate()
      {
      TI.Update();
      }
      Please let me know if this does not resolve your inquiry.
      Chris L.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by zstheorist, Today, 07:52 PM
      0 responses
      3 views
      0 likes
      Last Post zstheorist  
      Started by pmachiraju, 11-01-2023, 04:46 AM
      8 responses
      149 views
      0 likes
      Last Post rehmans
      by rehmans
       
      Started by mattbsea, Today, 05:44 PM
      0 responses
      5 views
      0 likes
      Last Post mattbsea  
      Started by RideMe, 04-07-2024, 04:54 PM
      6 responses
      33 views
      0 likes
      Last Post RideMe
      by RideMe
       
      Started by tkaboris, Today, 05:13 PM
      0 responses
      5 views
      0 likes
      Last Post tkaboris  
      Working...
      X