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

Return value for use in a strategy

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

    Return value for use in a strategy

    Hey guys,

    I have a general question so maybe you can point me the right direction. Let's say that I download an indicator that looks for divergence criteria and when met, paints a line on the chart for Longs and Shorts. How can I modify the code for this indicator to return something to my strategy so I can check for the Long or Short signal?
    If there are any examples that I could look at for reference, that will work too.

    I've attached the indicator, for reference.

    In 2 sections of this indicator, I see the code that draws the lines:

    Line 450:
    ///SHOWS DIVERGENCE LINES ON BOTTOM OF PRICE CANDLES
    Draw.Line(this, "low"+CurrentBar.ToString() + BarsAgo.ToString(), true, BarsAgo, Low[BarsAgo] - (TickSize * MarkerDistanceFactor),
    A, Low[A] - (TickSize * MarkerDistanceFactor), DivergenceColor, DivergenceDashStyle, DivergenceLineWidth);


    Line 494:
    ///SHOWS DIVERGENCE LINES ON BOTTOME OF INDICATOR HISTOGRAM
    Draw.Line(this, "Ilow"+CurrentBar.ToString() + BarsAgo.ToString(), true, BarsAgo, Indicator[BarsAgo],
    A, Indicator[A], divergenceColor, divergenceDashStyle, divergenceLineWidth);


    Would I put some sort of Return line in these sections somewhere?

    Thank you!
    Attached Files

    #2
    Hello PN720,
    Thanks for your post.

    No return method needed here. You can do something similar to the following reference sample that demonstrates how to expose indicator values that are not plots to a strategy



    Let me know if I can clarify anything in this sample.
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Hi Josh,

      Following the sample, I added code to the indicator and it's saying that it already contains a definition for my series. In the sample, I see the series being added up top and then again in Properties as a Public. When I do the same, NJT says it already contains a definition:

      // Added for Divergence signals to be read by Strategy
      private Series<bool> ShortDivergence;
      private Series<bool> LongDivergence;

      ....

      // Creating public properties that access our internal Series<bool> allows external access to this indicator's Series<bool>
      [Browsable(false)]
      [XmlIgnore]
      public Series<bool> ShortDivergence
      {
      get { return ShortDivergence; } // Allows our public BearIndication Series<bool> to access and expose our interal bearIndication Series<bool>
      }

      [Browsable(false)]
      [XmlIgnore]
      public Series<bool> LongDivergence
      {
      get { return LongDivergence; } // Allows our public BullIndication Series<bool> to access and expose our interal bullIndication Series<bool>
      }

      Comment


        #4
        Disregard. I see my error. The private Series and public series names need to be unique so I changed the capitalization. Thanks for the help.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by arvidvanstaey, Today, 02:19 PM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Started by mmckinnm, Today, 01:34 PM
        3 responses
        5 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by f.saeidi, Today, 01:32 PM
        2 responses
        8 views
        0 likes
        Last Post f.saeidi  
        Started by alifarahani, 04-19-2024, 09:40 AM
        9 responses
        55 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by Conceptzx, 10-11-2022, 06:38 AM
        3 responses
        60 views
        0 likes
        Last Post NinjaTrader_SeanH  
        Working...
        X