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

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.
    BertrandNinjaTrader Customer Service

    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.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by DJ888, Today, 10:57 PM
        0 responses
        2 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by MacDad, 02-25-2024, 11:48 PM
        7 responses
        158 views
        0 likes
        Last Post loganjarosz123  
        Started by Belfortbucks, Today, 09:29 PM
        0 responses
        7 views
        0 likes
        Last Post Belfortbucks  
        Started by zstheorist, Today, 07:52 PM
        0 responses
        7 views
        0 likes
        Last Post zstheorist  
        Started by pmachiraju, 11-01-2023, 04:46 AM
        8 responses
        151 views
        0 likes
        Last Post rehmans
        by rehmans
         
        Working...
        X