Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy accessing variable in indicator (almost there!)

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

    Strategy accessing variable in indicator (almost there!)

    Hi,

    I'm trying to make a strategy able to access a delta variable in my indicator.

    I added a new private variable BarDelta for it and added the following to make it accessible

    public double barDelta
    {
    // We need to call the Update() method to ensure our exposed variable is in up-to-date.
    get { Update(); return BarDelta; }
    }
    #endregion

    This works. The variable is exposed and I tried to reference it in the strategy as follows

    if (State == State.Configure)
    {
    VC = pjsVolumeCluster(1,10,200,true,0,0,20,70,false,fal se,true,3,1.4,100,false);
    }

    in onbar update

    d = VC.barDelta;

    Problem is, 'd' is always zero. I get no errors.

    I have checked the with indicator running and the variable is certainly being set.

    Does the inclusion of the code per above actually make the indicator instance run on the selected instrument, or do I have to do something else also? Adding it as an indicator to the chart proved the variable worked, but the strategy only see's zero as the value.

    Hope this makes sense.

    Thanks.

    #2
    Hello,

    Thank you for the post.

    I wanted to check, before you check the property, are you calling the indicator at all in OnBarUpdate?

    Without seeing the whole scope of the logic it is hard to say, but potentially the indicator is not being calculated if it is not being called in OnBarUpdate.

    Could you confirm if this is the case or provide a simple example that shows the syntax used to call the indicator in more detail?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi,

      No, not other than checking it's value.

      Like this ( stripped a few misc parts out for clarity, but I think all the info is there for you to understand.)

      public class pjsButtons : Strategy
      {
      private pjsVolumeCluster VC;
      private double d=0;

      }
      else if (State == State.Configure)
      {
      VC = pjsVolumeCluster(1,10,200,true,0,0,20,70,false,fal se,true,3,1.4,100,false);
      }

      protected override void OnBarUpdate()
      {
      d = VC.barDelta;
      }

      Draw.TextFixed(this,"db","\n\nDelta=" + d.ToString() +",K=" + I,TextPosition.TopRight);

      d always = zero

      Comment


        #4
        Hello,

        Thank you for the additional details.

        I tried this using a sample strategy and indicator but can only see the value being printed, potentially the indicator you are using is the cause.

        Depending on how the value is being calculated in the indicator, this may be the reason for this.

        Could you try the attached sample and verify you get Prints? If so, can you then compare the sample to your indicator to see if you are able to note any major difference in the way the value is set?

        So far I am unable to see any specific reason as to why the value is zero other than it may not be set when being accessed or that something in the indicator is not calculating as expected when hosted from a strategy.

        One further test would be to call the indicator from an Indicator instead of a strategy to see if this is specifically related to the strategy calling that indicator.

        I look forward to being of further assistance.
        Attached Files
        JesseNinjaTrader Customer Service

        Comment


          #5
          Your test file worked OK. Thank you for your help.

          I figured it out. The indicator required 'Tick Replay' to the turned on. Once I did that in the chart that hosts the strategy, the variable started reporting non-zero results.

          Thanks for helping me get to a solution.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by WHICKED, Today, 12:56 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by cre8able, Today, 01:16 PM
          0 responses
          1 view
          0 likes
          Last Post cre8able  
          Started by chbruno, 04-24-2024, 04:10 PM
          2 responses
          47 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by WHICKED, Today, 12:45 PM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by samish18, Today, 01:01 PM
          0 responses
          5 views
          0 likes
          Last Post samish18  
          Working...
          X