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 Brevo, Today, 01:45 AM
        0 responses
        6 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        3 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        242 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        384 views
        1 like
        Last Post Gavini
        by Gavini
         
        Started by oviejo, Today, 12:28 AM
        0 responses
        6 views
        0 likes
        Last Post oviejo
        by oviejo
         
        Working...
        X