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

Need Help With UserDefinedMethods

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

    Need Help With UserDefinedMethods

    Hello

    I would like to create a strategy that references another userdefined method. I have already looked at the available template and created a Class with Fibonacci variables. What I want to do is -

    -Pass Point A and B to this Userdefined method
    - Have the method return Fibonacci price levels.
    -Repeat as time goes on.

    How do I overload the userdefined method to keep updating the Fibonacci price levels? The function inside the method only returns a single variable. How do I make it return an entire list/array of price ratios back to my main strategy ?

    Thanks

    #2
    Hello,

    Thank you for the post.

    I would need to see what you have created so far to really explain this in context to what you have, but in general, you can make a method return whatever you want and take whatever input you need. This is a C# concept and not specific to NinjaScript.

    Here is an example of a user-defined method that takes no input and just returns a list that contains a few values. This is simply to illuminate how the return works:

    Code:
     partial class Strategy
    {
        public [B]System.Collections.Generic.List<double>[/B] GetLevels()
        {
    	[B]System.Collections.Generic.List<double> tempList = new System.Collections.Generic.List<double>();[/B]
    	tempList.Add(2000);
    	tempList.Add(2100);
    	tempList.Add(2200);
    	[B]return tempList;[/B]
        }
    }
    You can then configure overloads for your points whether that be bar or price information like the following:

    Code:
    partial class Strategy
    {
        public System.Collections.Generic.List<double> GetLevels([B]double priceOne, double priceTwo[/B])
        {
    	System.Collections.Generic.List<double> tempList = new System.Collections.Generic.List<double>();
    	tempList.Add(priceOne);
    	tempList.Add(priceOne + 10);
    	tempList.Add(priceOne + 20);
    	return tempList;
        }
    }
    You can modify the overloads to be whatever values you need to input, and the return value to whatever type of object you want back from calling the method.

    From another strategy it would look like the following to call the method:

    Code:
      protected override void OnBarUpdate()
    {
    	System.Collections.Generic.List<double> levels = GetLevels(Close[0], High[0]);
    }
    For each bar, the method is called and returns a new list of doubles.

    you don't have to use a list either, whatever object is better for your goal. That could be a simple type like an int, or double, or a more complex type like a list or dictionary.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      You are the man! That's what I needed. Thank You. Ninjatrader support is the best. I wish there were more brokerages that used Ninjatrader platform. Do you know if there is anyway I can connect to Tradersway account through Ninjatrader?

      Comment


        #4
        Hello,

        Thank you for the kind comment,

        Unfortunately, I am unaware of any way this could be used with the platform currently but I will put in a feature request on your behalf.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by chartchart, 05-19-2021, 04:14 PM
        3 responses
        577 views
        1 like
        Last Post NinjaTrader_Gaby  
        Started by bsbisme, Yesterday, 02:08 PM
        1 response
        15 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by prdecast, Today, 06:07 AM
        0 responses
        3 views
        0 likes
        Last Post prdecast  
        Started by i019945nj, 12-14-2023, 06:41 AM
        3 responses
        60 views
        0 likes
        Last Post i019945nj  
        Started by TraderBCL, Today, 04:38 AM
        2 responses
        18 views
        0 likes
        Last Post TraderBCL  
        Working...
        X