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

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 Stanfillirenfro, Yesterday, 09:19 AM
          7 responses
          51 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by TraderCro, 04-12-2024, 11:36 AM
          4 responses
          69 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Mindset, Yesterday, 02:04 AM
          1 response
          15 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by agclub, 04-21-2024, 08:57 PM
          4 responses
          18 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by Irukandji, Today, 04:58 AM
          0 responses
          6 views
          0 likes
          Last Post Irukandji  
          Working...
          X