Announcement

Collapse
No announcement yet.

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.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      90 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      135 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      119 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      69 views
      0 likes
      Last Post PaulMohn  
      Working...
      X