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 Hwop38, 05-04-2026, 07:02 PM
        0 responses
        164 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Started by CaptainJack, 04-24-2026, 11:07 PM
        0 responses
        317 views
        0 likes
        Last Post CaptainJack  
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        245 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        350 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        179 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Working...
        X