Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

user defined methods and IDataSeries

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

    user defined methods and IDataSeries

    OK, So I successfully coded key reversal bar statements in the userdefinedmethods folder, and then used in my indicator...great! see below.

    But it's a little obnoxious to have to pass two different IDataSeries, whether it's Close, Low, or High - also i have to remember which to do for key reversal up or key reversal down. Is there a way that I can reduce shrink this code a bit, where I just have to pass one dataseries? If so, how?

    I realize that this is not a lot of code, but I am doing this so I can learn ninjascript.

    Thanks,
    Matt



    Section 1
    userdefinedmethods.cs

    Code:
      public bool IsKeyReversalUp (IDataSeries pricesClose, IDataSeries pricesLow){
                if ( (pricesLow[0] <= pricesLow[1]) && pricesClose[0] > pricesClose[1]){
                    return true;
                }else return false;
            }
            
            public bool IsKeyReversalDown (IDataSeries pricesClose, IDataSeries pricesHigh){
                if ( (pricesHigh[0] >= pricesHigh[1]) && pricesClose[0] < pricesClose[1]){
                    return true;
                }else return false;
            }
    Myindicator.cs

    Code:
                if (IsKeyReversalUp(Close, Low)) {
    DO SOMETHING
                }
                if (IsKeyReversalDown(Close, High)) {
    DO SOMETHING
    }

    #2
    Hi Matt, nice exercise, but I'm not sure why you would need to pass anything in at all - you could hardcode the user defined method to use the respective double values for the comparisons to arrive at the needed pattern outcomes.

    Comment


      #3
      Hi Bertrand,

      OK, I did as you suggested, and it worked! Why did I not even try that? because I was looking at UserDefinedMethods from the help section and I copied from that example. That example is a bit misleading then. Unless If i missed something there.



      BTW, if I want to copy and paste a link to an example in the ninjatrader help, like UserDefinedMethods section, how do I do that?

      Comment


        #4
        Matt, the example are for demonstration purposes to show functionality - you can right click on the page and copy in the shortcut to it.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        580 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        336 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        554 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        552 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X