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.

    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.

        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 NullPointStrategies, Today, 05:17 AM
          0 responses
          38 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          124 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          64 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          41 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X