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

questions about position management in custom strategy

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

    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.

    #2
    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.
    JesseNinjaTrader Customer Service

    Comment


      #3
      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, 01:07 AM.

      Comment


        #4
        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 Files
        JesseNinjaTrader Customer Service

        Comment


          #5
          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

          Comment


            #6
            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, 09:25 AM.
            JesseNinjaTrader Customer Service

            Comment


              #7
              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.

              Comment


                #8
                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.



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

                Comment


                  #9
                  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 ?

                  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, 02:17 AM.

                  Comment


                    #10
                    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.
                    JesseNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Irukandji, Today, 09:34 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post Irukandji  
                    Started by TraderBCL, Today, 04:38 AM
                    3 responses
                    24 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by WeyldFalcon, 08-07-2020, 06:13 AM
                    11 responses
                    1,423 views
                    0 likes
                    Last Post jculp
                    by jculp
                     
                    Started by RubenCazorla, Today, 09:07 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post RubenCazorla  
                    Started by BarzTrading, Today, 07:25 AM
                    2 responses
                    29 views
                    1 like
                    Last Post BarzTrading  
                    Working...
                    X