Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question on passing data from an indicator to a strategy

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

    Question on passing data from an indicator to a strategy

    I've built an indicator and I'm trying to send over a status of a data point to a strategy.

    Indicator code I'm trying to pass:
    Code:
    public SlopeStatus currentSlope;
    
    public enum SlopeStatus
    {
    UpShallow,
    UpSteep,
    DownShallow,
    DownSteep,
    Flat
    }
    Setting it like this in the indicator
    Code:
    if (xSlope <= -angle2)
    {
    PlotBrushes[0][0] = EmaSlopeDownAngleSteep;
    PlotBrushes[1][0] = EmaSlopeDownAngleSteep;
    PlotBrushes[2][0] = EmaSlopeDownAngleSteep;
    currentSlope = SlopeStatus.DownSteep;
    }
    else
    if (xSlope <= -angle1)
    {
    PlotBrushes[0][0] = EmaSlopeDownAngleShallow;
    PlotBrushes[1][0] = EmaSlopeDownAngleShallow;
    PlotBrushes[2][0] = EmaSlopeDownAngleShallow;
    currentSlope = SlopeStatus.DownShallow;
    }
    else
    {
    PlotBrushes[0][0] = EMAflat;
    PlotBrushes[1][0] = EMAflat;
    PlotBrushes[2][0] = EMAflat;
    currentSlope = SlopeStatus.Flat;
    }
    All of this works fine. However when I pull in the data, it's ALWAYS the default Enum value of 0.
    Code:
    case MarketPosition.Flat:
    switch (momentumBands1.currentSlope)
    {
    case Indicators.MomentumBands.SlopeStatus.Flat:
    return;
    case Indicators.MomentumBands.SlopeStatus.UpShallow:
    ExecuteLongEntry("Going Long");
    break;
    case Indicators.MomentumBands.SlopeStatus.UpSteep:
    ExecuteLongEntry("Going Long");
    break;
    case Indicators.MomentumBands.SlopeStatus.DownShallow:
    ExecuteShortEntry("Going Short");
    break;
    case Indicators.MomentumBands.SlopeStatus.DownSteep:
    ExecuteShortEntry("Going Short");
    break;
    }
    break;
    Is my approach here incorrect?


    Thanks!

    #2
    Hello DogEars,

    Thanks for the post.

    You can find an example of exposing non-plotted data in the following link. The same concept would apply to your enum public property, you would need to use the Update() method and a backing field. It would be the same way shown as the ExposedVariable:

    Code:
    public double ExposedVariable
    {
    // We need to call the Update() method to ensure our exposed variable is in up-to-date.
    get { [B]Update(); [/B]return exposedVariable; }
    }



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

    Comment


      #3
      Interesting, thanks for sending that.

      I followed the pattern there and when I enable the indicator it immediately hard crashes Ninja, no warning.

      Comment


        #4
        Hello DogEars,

        From that detail it sounds like you have incorrectly followed the sample, a hard crash like that would generally be caused by a circular dependency. For example calling the public property from within its self:

        Code:
        public SlopeStatus [B]currentSlope[/B] { get { return [B]currentSlope[/B]; } }
        The sample uses a private variable so you should end up with a capitalized public property and lower case private property:

        Code:
        private SlopeStatus currentSlope;
        public SlopeStatus CurrentSlope { get { return currentSlope; } }
        In your code you would be setting the lower case currentSlope to the value, the external script would get the public upper case property.


        If you are still having difficulty please provide a sample of what you made by following the other sample.

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

        Comment


          #5
          Hey, thanks.

          I caught that after I started looking at it again, so dumb.

          The update(); was the key, appreciate the help!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by gustavobp, Today, 03:15 AM
          0 responses
          5 views
          0 likes
          Last Post gustavobp  
          Started by gustavobp, Today, 03:00 AM
          0 responses
          5 views
          0 likes
          Last Post gustavobp  
          Started by nicbizz, Today, 02:14 AM
          0 responses
          5 views
          0 likes
          Last Post nicbizz
          by nicbizz
           
          Started by Ringer13, Today, 01:59 AM
          0 responses
          7 views
          0 likes
          Last Post Ringer13  
          Started by NINZAMANA, 02-06-2025, 09:03 AM
          2 responses
          24 views
          0 likes
          Last Post Fertryd2  
          Working...
          X