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

Returning a method from an indicator

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

    Returning a method from an indicator

    Hey guys,

    I downloaded this simple indicator (attached) that changes the slope color between a rising and falling EMA. I need a little help on how I can detect when it's rising and falling from my strategy. I tried:

    private EMASlopeColor EMASlopeInd;

    EMASlopeInd = EMASlopeColor(20, Brushes.Lime, Brushes.Red);
    AddChartIndicator(EMASlopeInd);

    If (EMASlopeInd.IsRising == true)
    Print ("IsRising");

    But it tells me that IsRising is a method. Can you help point me the right way?

    Thanks!

    #2
    Indicator attached..
    Attached Files

    Comment


      #3
      Hello PN720,

      Thanks for your post,

      Please try: if (IsRising(EMASlopeInd))

      Alternately if you prefer to see the == true you can write it as if (IsRising(EMASlopeInd) == true)

      Either way will work.

      Also, please make sure you are doing a Currentbar check to ensure you have at least a few bars loaded before checking the isRising() condition.
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_Paul View Post
        Hello PN720,

        Thanks for your post,

        Please try: if (IsRising(EMASlopeInd))

        Alternately if you prefer to see the == true you can write it as if (IsRising(EMASlopeInd) == true)

        Either way will work.

        Also, please make sure you are doing a Currentbar check to ensure you have at least a few bars loaded before checking the isRising() condition.
        Hi Paul,

        This worked perfectly, thank you!

        One follow-up question.. what is the correct syntax if I wanted to check prior bar?

        I tried both of these and neither worked:

        if (IsRising[1](EMASlopeInd) == true)

        if (IsRising(EMASlopeInd[1]) == true)

        Comment


          #5
          Hello PM720,

          Thanks for your reply.

          The IsRising() (and IsFalling()) will only provide the lookback of the current bar to the previous bar, there is no adjustment or indexing. It is best to think of them as describing the current condition compared to the previous bar.

          You can accomplish the same thing by comparing EMASlopeInd[0] to EMASlopeInd[1] or to continue further back EMASlopeInd[1] to EMASlopeInd[2], etc. etc,

          Example: if (EMASlopeInd[1] >EMASlopeInd[2] && IsRising(EMASlopeInd)) would be the same as:

          if (EMASlopeInd[1]> EMASlopeInd[2] && EMASlopeInd[0] > EMASlopeInd[1])

          Paul H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by techgetgame, Yesterday, 11:42 PM
          0 responses
          9 views
          0 likes
          Last Post techgetgame  
          Started by sephichapdson, Yesterday, 11:36 PM
          0 responses
          2 views
          0 likes
          Last Post sephichapdson  
          Started by bortz, 11-06-2023, 08:04 AM
          47 responses
          1,615 views
          0 likes
          Last Post aligator  
          Started by jaybedreamin, Yesterday, 05:56 PM
          0 responses
          10 views
          0 likes
          Last Post jaybedreamin  
          Started by DJ888, 04-16-2024, 06:09 PM
          6 responses
          20 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Working...
          X