Go Back   NinjaTrader Support Forum > NinjaTrader 8 > Strategy Development

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

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 02-07-2017, 09:12 PM   #1
emilien
Junior Member
 
Join Date: Oct 2014
Posts: 22
Thanks: 7
Thanked 1 time in 1 post
Default questions about position management in custom strategy

Hi,
I'm just learning how to code with Ninjascript and trying to implement a strategy where I can enter trades and manage positions while trading using ChartTrader at the same time. I started from the sample NT8 - LONG SHORT Toolbar Buttons provided in Strategies Download. Here are my questions:

(1) I have a Stop Loss order in my strategy that is submitted after the EnterLong() order get filled. When I enter using my custom strategy but then use ChartTrader to take partial position off, the shares size in the stop loss order doesn't change. How do I adjust that ?

(2) When I move my stop loss order by clicking on chart, the stop loss order is moved back to the original location set by my strategy. How do I prevent that to happen ?

(3) Is it possible for the custom strategy to use a pre-defined ATM strategies on ChartTrader. If yes, how to implement that ?

(4) In the current code, when I click on LONG button, I get in the trade. I want to be able to get more entries without having to exit the position, but those entries have to be initiated by me clicking the button again instead of automatically added. How do I modify the configuration or code to implement that ?

Thanks.
emilien is offline  
Reply With Quote
Old 02-08-2017, 09:37 AM   #2
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 3,632
Thanks: 28
Thanked 941 times in 878 posts
Default

Hello emilien,

Thank you for the post.

I believe the simple answer to these questions is that the specific sample you are using is not really intended for the actions you are trying. The sample is more of a concept but in general a Strategy would not be the best choice for adding order submission buttons if you want to also manually interact with the orders in other tools.

A strategy by nature has virtual reporting that is separate from the manual orders/actions you may submit/modify while it is running. For the strategy to register changes in Position, Order quantity, order placement or most other order items, that strategy would need to make those changes its self. This means any changes you do in the ChartTrader would not be recognized and may cause complications for the logic the strategy executes or could potentially stop the strategy. This would also mean that any action you need to complete, you would need to program a button for and also not use the existing tools like ChartTrader.

You would likely need to decide if you want to continue to use a Strategy specifically, which would more or less control the orders for you and where you would need to develop logic for each action you want. Or the other suggestion would be to create a custom tool which does not use the strategy methods and instead uses the normal order entry methods. This would be known as an Addon and we have samples of submitting orders using an addon in the sample here: http://ninjatrader.com/support/helpG...t_overview.htm

In general addons would be the suggested choice for any type of tool where you need to submit orders but also want to manage those orders from the other existing tools in the platform. Because you would submit orders directly to the account, other tools can also manage the orders where as a strategy would want to specifically manage the orders it submits on its own. Addons can create entirely new windows or modify existing chart windows to add buttons or other items, this would really be up to your design.

I would likely suggest using an addon opposed to a strategy specifically because you want to interact with the order in the existing tools like chart trader. Addons also give much more flexibility in regard to using ATM strategies as well which there is also a sample of in the above link. Strategies can also use ATM strategies but in a fairly limited way, you can see an example of this concept in the included SampleATMStrategy.

For an example of a chart button from an addon, please see this link: http://ninjatrader.com/support/forum...75&postcount=2




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:
Old 02-08-2017, 06:19 PM   #3
emilien
Junior Member
 
Join Date: Oct 2014
Posts: 22
Thanks: 7
Thanked 1 time in 1 post
Default

Thank you so much for pointing me in the right direction.

So I think I'll need to build an Add on window that works with Chart window. How do I "link" my Add on to Chart window ? I want to basically have my own window (similar to Chart Trader) that has my custom buttons and should have access to chart control. In a Strategy, I can use ChartControl, OnRender(). How do I do similar with Add On ?

Does the SampleAddonChartButton in your link work in NT 8 ? It compiled without any problem the first time I imported it. However, after I restarted NT 8 as suggested, I got error messages such as this "An assembly with the same identity 'InfragisticsWPF4.DataPresenter.v15.1, Version=15.1.20151.2055, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb' has already been imported. Try removing one of the duplicate references.".
Last edited by emilien; 02-09-2017 at 01:07 AM.
emilien is offline  
Reply With Quote
Old 02-09-2017, 09:11 AM   #4
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 3,632
Thanks: 28
Thanked 941 times in 878 posts
Default

Hello emilien,

First off regarding the error, I believe this may be coincidence that this occurred near the same time as importing the script.

The error is specifically that there is a duplicate reference that NinjaTrader uses. To correct this you could:
  1. Open a NinjaScript editor
  2. Right click -> References.
  3. In the references list look for InfragisticsWPF4.DataPresenter and ensure there is only one row for this reference. If there are two, remove the second
  4. click OK then compile

I attached an image of the default references for the x64 bit platform so you can make sure the default references all exist and there are no duplicates.

Regarding the linking, this depends on what you mean on linking. There would be two concepts you could approach in regard to an addon being "linked".

The first idea would be that of the sample I provided in the last message or that you "observe" created windows from the addon, once a specific window is found (chart) a button is added to that charts toolbar.
The linking part of this concept is that you have physically added a control to the charts window which will execute whatever code from the addon you want. That control could open another window like a custom chart trader that you also add, or just do an action like submit an order to an account, that's really up to your design. If you choose to open a window, because you have the charts instance you could pass the instance to the window for access if needed.

The second approach is that of the addon sample we have in the help guide: http://ninjatrader.com/support/helpG...t_overview.htm
This addon actually requests and subscribes to its own data, has a physical account selector and many other examples of the NinjaTrader controls. One of those controls is the Link buttons you see in the toolbar of each tool. This system lets your tool link up to the Instrument or Interval change events that use the color code system. For a completely custom tool that does not depend on other things like a chart, this would be the approach to take but is considerably more difficult because of the amount of syntax needed.

Based on these two approaches you could decide a direction, I couldn't suggest either more than the other as this really depends on what your tool specifically needs to do. I would say that the first approach is likely easier and seems closer to what you have mentioned you needed.

As far as using OnRender and other Overrides, this is not really a concept of the addon its self, the addon is more of an observer that can effect things it observes like a window. Things that can render like an Indicator would have OnRender because this type is applied directly to the chart and should render.

While you can access objects like ChartControl or even indicators, in a lot of cases there is specific core logic that may not be executed by trying to do things from an observation stand point. For example accessing an Indicator may not produce an expected result or possibly even have no effect at all where as changing a property of the actual ChartControl would work in certain cases. It really depends on what you are trying. For addons and any GUI items really, I generally suggest to try something the way you think it should work, if it does not provide a sample of specifically that concept and we can see if there may be another way around that using supported syntax.

You will find a lot of good help on this concept on the forums here, unfortunately a lot of that content is in the archived beta section because many of the beta testers pioneered this part of NinjaScript. I would suggest to look through older posts related to addons as our support and users both have provided many different samples on many concepts related to addons.

I look forward to being of further assistance.
Attached Images
File Type: png NinjaTrader_2017-02-09_07-41-59.png (30.8 KB, 2 views)
NinjaTrader_Jesse is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Jesse for this post:
Old 02-10-2017, 08:52 AM   #5
balltrader
Member
 
Join Date: Dec 2015
Posts: 34
Thanks: 26
Thanked 1 time in 1 post
Default What is the difference and reason for the duplicate?

Hi Jesse,

one appears to be in /bin, the other in /bin64

Please explain how there are 2 references

(is it from importing an indicator script that included both references?)
(is it from 1 indicator script referencing the /bin version, and a different indicator script referencing the /bin64 version?)

(which version is best to keep?)
(if NT8 is always launched from the 64bit version icon, is it safe to delete the /bin version?)
(if NT8 is launched without the 64bit icon, and the /bin version is missing, will indicators fail?)

thanks
balltrader is offline  
Reply With Quote
Old 02-10-2017, 09:22 AM   #6
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 3,632
Thanks: 28
Thanked 941 times in 878 posts
Default

Hello balltrader,

I am unsure of the events that would have lead to having both the 32 bit and 64 bit references, this is possibly from an update but I could not say with certainty what caused this specifically.

The solution would be to remove the one for the version you are not using.
For example if you used the 64 bit NinjaTrader icon, remove the reference that lists "bin".
Otherwise if you are using the 32 bit version, remove the one that lists "bin64"

I look forward to being of further assistance,
Last edited by NinjaTrader_Jesse; 02-10-2017 at 09:25 AM.
NinjaTrader_Jesse is offline  
Reply With Quote
Old 02-14-2017, 11:35 PM   #7
emilien
Junior Member
 
Join Date: Oct 2014
Posts: 22
Thanks: 7
Thanked 1 time in 1 post
Default

I think I didn't phrase my questions very well. I want to implement my own chart trader window (an Add-on) that allows me to do the following:

1. click on buttons to submit orders when some conditions on price and indicator values are met.
I've looked at the Add-on sample code and I know I can request data in an Add-on by using BarRequest. However, I'm not sure how I can refer to the current bar and previous bars.

- How to specify "current bar high goes higher than previous bar high" ? something similar to High[0] >= High[1] if I do this in an indicator or strategy.

- How do I check if a bar has just closed ?

- How do I access an indicator value from an Add-on ? I read in the guide that bars data from a BarRequest cannot be used for indicator calculation.

2. click on chart to set a stop or entry level before entering the trade
This is why I need access to Chart Control. (I used the word "link" which was ambiguous). I think I'll do what you suggested above (if I understand correctly). I'll have an indicator that places a button somewhere on chart window and open my Add-on window from that button then pass the reference of the Chart Control (available in my indicator) to that Add-on window.

3. use the pre-defined ATM strategies to manage my positions, move stop and target by clicking on chart.
I haven't tried but I understand orders submitted from an Add-on can be managed by the original Chart Trader easily.
emilien is offline  
Reply With Quote
Old 02-16-2017, 09:10 AM   #8
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 3,632
Thanks: 28
Thanked 941 times in 878 posts
Default

Hello emilien,

In this case, you would likely need to take the knowledge gained from the addon examples provided previously and use similar logic in an indicator rather than an addon.

You could use the following indicator add button example to access the charts GUI items, I will also provide a link on how to access the chart trader and ATM control.
http://ninjatrader.com/support/forum...7&postcount=21
http://ww.ninjatrader.com/support/fo...44&postcount=7

In this case, the concept would be to apply your item to the chart, your item looks for existing controls like the chart trader and accesses them. you can check items like selected ATM strategies, or get data from the chart like Close[0]. This concept also allows you to access or call on other indicators just like a normal indicator you may create. You could do other more complex actions like create new windows or really any GUI items you might do in an addon in this situation as well. You can note the major difference is how you find the parent window rather than observing when windows open in the platform.


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:
Old 02-17-2017, 02:07 AM   #9
emilien
Junior Member
 
Join Date: Oct 2014
Posts: 22
Thanks: 7
Thanked 1 time in 1 post
Default

Hi Jesse,

I still can't get my head around what you mentioned about accessing data from the chart. Could you please elaborate on that ?

Quote:
Originally Posted by NinjaTrader_Jesse View Post
In this case, the concept would be to apply your item to the chart, your item looks for existing controls like the chart trader and accesses them. you can check items like selected ATM strategies, or get data from the chart like Close[0]. This concept also allows you to access or call on other indicators just like a normal indicator you may create.
What "item" are you talking about ? an indicator or an Add-on ?

I can get the reference to chart window from the OnWindowCreated() in an Add-on so I assume accessing existing controls is similar to what has been done in the samples. However, I still can't see how I can access data in the same way as in an indicator. I tried Close[0] in an Add-on but it wasn't available.

One more question. Although I have only one chart window open, the OnWindowCreated is always called twice (the window is of Chart type). Do you have any idea why that happens ?
Last edited by emilien; 02-17-2017 at 02:17 AM.
emilien is offline  
Reply With Quote
Old 02-17-2017, 11:43 AM   #10
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 3,632
Thanks: 28
Thanked 941 times in 878 posts
Default

Hello emilien,

The item I am referring to is the item you are creating.

In the last email, I detailed that for what you are trying to do, using the AddonBase is likely not the best choice because you want to access indicator data. In the case of creating an AddonBase and observing other windows, there is currently no documented way to interface with series or indicators in that form. What I had mentioned in the last email is that you can instead use an Indicator which does have access to the charts data or other indicators values and just use the other samples as a guide on how to add to the GUI.

The indicator by nature can use the price data of the chart it is applied to which would eliminate the need to subscribe to data and you could also call other indicators if needed or check price conditions. You can then use the methods that are documented in the Addon section of the help guide to submit orders or do other actions in the platform from this indicator.

Regarding the duplication of the OnWindowCreated, do you have more than one addon currently enabled that is printing? I am not certain why the override would get called twice for a single window.

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
Position management fiddy Strategy Development 1 01-07-2016 11:09 AM
Backtesting Strategy: Account Management + Position Sizing Kamisyed General Development 3 02-25-2014 07:17 AM
Account Management, Portfolio Management, Position Sizing, Multiple Strategies, etc. Anagoge Strategy Development 7 12-07-2008 05:33 AM
2 questions about order management Sidhartha General Development 7 05-01-2008 09:54 AM
Risk Management Suggestions & Other Questions JangoFolly Suggestions And Feedback 4 11-14-2007 06:04 PM


All times are GMT -6. The time now is 09:42 AM.

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.