Go Back   NinjaTrader Support Forum > NinjaTrader 7 > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 02-17-2017, 12:43 AM   #1
MyFirstMillion
Junior Member
 
Join Date: Dec 2016
Posts: 27
Thanks: 4
Thanked 0 times in 0 posts
Default 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
MyFirstMillion is offline  
Reply With Quote
Old 02-17-2017, 08:28 AM   #2
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 3,644
Thanks: 28
Thanked 945 times in 882 posts
Default

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 System.Collections.Generic.List<double> GetLevels()
    {
	System.Collections.Generic.List<double> tempList = new System.Collections.Generic.List<double>();
	tempList.Add(2000);
	tempList.Add(2100);
	tempList.Add(2200);
	return tempList;
    }
}
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(double priceOne, double priceTwo)
    {
	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.
NinjaTrader_Jesse is offline  
Reply With Quote
Old 02-17-2017, 10:27 AM   #3
MyFirstMillion
Junior Member
 
Join Date: Dec 2016
Posts: 27
Thanks: 4
Thanked 0 times in 0 posts
Default

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?
MyFirstMillion is offline  
Reply With Quote
Old 02-17-2017, 12:39 PM   #4
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 3,644
Thanks: 28
Thanked 945 times in 882 posts
Default

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.
NinjaTrader_Jesse is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Jesse for this post:
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
UserDefinedMethods GrumpyTrader Version 8 Beta 17 10-05-2016 05:32 PM
UserDefinedMethods.cs ? koganam Version 8 Beta 4 05-11-2015 08:15 AM
UserDefinedMethods ScottB Platform Technical Support 7 09-28-2010 02:34 PM
UserDefinedMethods ScottB General Development 2 09-25-2010 11:53 AM
userdefinedmethods 8DTK8 Strategy Development 4 02-22-2009 08:49 AM


All times are GMT -6. The time now is 02:52 PM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content. Visit the CFTC resources for education regarding the industry and signs of fraud.