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

using ATM strategy in strategy

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

    using ATM strategy in strategy

    Hello i wanted to clarify on using ATM strategies within strategy .... initialised with ATMStrategyCreate() etc - if one is planning to use the Strategy Analyser for optimisation ; in addition to not being able to backtest is it not feasible for planning to use strategy analyser? In that one needs to use Managed orders or unmanaged approach IOrder within strategy to be able to use Strategy optimiser?

    Additionally i am working on something that will take inputs from a csv like file in order to vary inputs and settings for the strategy logic. This is an alternative to using parameters to define run of strategy and will have different settings depending on instrument etc.
    Again if i adopt the csv input file approach for parameters does this then negate the benefit and ability to use Strategy Analyser. Strategy Analyser works based on paramter settings and range of settings used by optimiser?

    On the question of if i dont use ATM strategies within the strategy. Is it feasible to manage the stop to breakeven aspect of atm using Iorder approach - the answer i know is yes for 1 contract. Is it more tricky or just needs the right code to manage the stop profit and breakeven for say 2 or 3 or more contracts in a strategy and to keep and manage which belongs to which IOrder and which is filled etc? IE manage the SETS of profit stop and breakeven for each contract/group of contracts. Yes using the ATM makes it more elegant and less complex.
    Using the managed approach i dont see it is possible to have stop moved to breakeven or an amount near entry or above - at least from what i have inspected?

    thank you

    #2
    Hi Soulfx

    I'm sure one of the brilliant Ninja staff will be able to help you with this.

    I'm posting this just to refer to a thread I started at:

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


    Please see post #1 where I gave a draft of code to enable breakeven without reference to ATMs.

    I've since seen the first line of the if statement should be changed to:

    Code:
    Position.GetProfitLoss([B][COLOR="Blue"]High[/COLOR][/B][i]...
    Any improvements to this welcomed!

    Comment


      #3
      Thanks Arbuthnot for helping out here and there is some overlap in what you are trying to effect; though not sure if doing this for 1 or more contract in your code. Hopefully ninja will still respond to my questions
      thanks

      Comment


        #4
        Hi soulfx,

        Thanks for your post.

        When Atm strategy methods are used, this will cause the strategy engine to no longer recognize your trades.

        This means that an ExitLong() will not work for an entry made with AtmStrategyCreate(). Also, the performance can not be measured.


        With the optimizer, you are correct. Only the public parameters will be available to optimize. Any values that are not public, such as private variables, or variables created from reading a file, cannot be optimized over.

        You can still optimize the strategy, but you will not be able to optimize the variables created from the file.

        Yes, you can move a stop to breakeven using logic in your code.

        For example, you can check that the current price is greater than or equal to the entry price of your order plus a certain amount of ticks. If it is, change the stop price to the entry price.

        You can change the price of any stop loss (or all stop losses) by calling SetStopLoss() at any time with a new price. If the stop loss is using a from Entry Signal, then only the stop loss with that from Entry Signal will be set to the new price (in case you are working with multiple orders).

        For example:

        if (Position.MarketPosition == MarketPosition.Long && Close[0] >= Position.AvgPrice + 10 * TickSize)
        {
        SetStopLoss(CalculationMode.Price, Position.AvgPrice);
        }

        This would move the stop loss to break even after 10 ticks of profit have been reached.

        http://www.ninjatrader.com/support/h...etstoploss.htm
        Last edited by NinjaTrader_ChelseaB; 12-15-2014, 11:27 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks for confirming on the ATM strategy and the input file and limitations then of use of Strategy Analyser.

          So in the case of multiple orders using the SetStopLoss(fromEntrySignal, mode, value, false) variation i can map the stop loss to the right entry and for example in the case of 2 contracts there would be 2 separate order submissions in the managed order code section with different fromEntrySignal names which would then be linked to the same symbols with 2 separate SetStopLoss() calls in the initialise section? If i wanted to managed up to 3 or 4 contracts with this approach is it a problem to the strategy to set up 4 separate SetStopLoss() and 4 separate SetProfitTarget() calls but for some runs to the strategy only actually submit 1 or 2 orders? These amounts would need to be defined in the strategy or as a separate parameter and NOT using the default quantity in the strategy setting. Just trying to consider this approach vs ATM as you state cannot do performance optimisation. So in a sense there is some flexibility to the managed order approach.
          Also given this and the strategy only submits on bar close = true - the section for managing stop loss changes could be filtered using FirstTickOfTheBar logic = false around stop management and = true around other sections that are only to be processed and calculated on bar close.
          Is this then more inefficient than using ATM strategy or the compromise to have the control in the strategy?
          thanks for assistance

          Comment


            #6
            When Atm strategy methods are used, this will cause the strategy engine to no longer recognize your trades.

            This means that an ExitLong() will not work for an entry made with AtmStrategyCreate(). Also, the performance can not be measured.
            Just to clarify on comment above .. does this mean that calls like this in the strategy

            Performance.RealtimeTrades.TradesPerformance.Point s.CumProfit

            can not be performed when using the ATM strategy approach?

            Comment


              #7
              Hello soulfx,

              That is correct. The Performance collection will not include trades made with Atm strategy methods.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hello there sorry my reply before yours perhaps meant you didnt see my questions below this one
                thanks

                Comment


                  #9
                  Hi soulfx,

                  Yes, I missed post #5.

                  When using SetStopLoss, yes, the signal name of the entry and associated from entry signal of the stop will separate the stop losses to particular orders. This is also the case for exit orders.

                  An order with multiple contracts (quantity) is not multiple orders. This would be one order with multiple contracts. If you want the stop loss applied to each contract, make each order with a quantity of 1 and use a signal name.


                  You can use logic to submit as many separate orders you want. Each order can be protected with a stop loss and profit target if a stop loss and profit target are applied to each order. (Either with the fromEntrySignal, or by not using a fromEntrySignal)


                  If you plan to use CalculateOnBarClose as false and use FirstTickOfBar to manage the stop loss, I would not imagine this is any more or any less efficient than using an Atm Strategy as long as at the logic is about the same. In other words if you just check the price for a break even, the efficiency will likely be about the same.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_ChelseaB View Post
                    Hello soulfx,

                    That is correct. The Performance collection will not include trades made with Atm strategy methods.
                    Is this something that will be possible in forthcoming NT8 version to be able to do this with better integration and flexibility in using ATM strategies from within a strategy?

                    Comment


                      #11
                      Originally posted by NinjaTrader_ChelseaB View Post
                      Hi soulfx,

                      Yes, I missed post #5.

                      When using SetStopLoss, yes, the signal name of the entry and associated from entry signal of the stop will separate the stop losses to particular orders. This is also the case for exit orders.

                      An order with multiple contracts (quantity) is not multiple orders. This would be one order with multiple contracts. If you want the stop loss applied to each contract, make each order with a quantity of 1 and use a signal name.


                      You can use logic to submit as many separate orders you want. Each order can be protected with a stop loss and profit target if a stop loss and profit target are applied to each order. (Either with the fromEntrySignal, or by not using a fromEntrySignal)


                      If you plan to use CalculateOnBarClose as false and use FirstTickOfBar to manage the stop loss, I would not imagine this is any more or any less efficient than using an Atm Strategy as long as at the logic is about the same. In other words if you just check the price for a break even, the efficiency will likely be about the same.

                      thanks for clarifying as i meant submitting separate orders with different quantities or quantity 1 each thus to be able to manage with separate stop profit and breakeven levels.

                      On above i see it would need to be CalculateOnBarClose = false in order to be able to adjust the stop loss and checking sections of code using FirstTickOfBar and this would be false to manage section on changing stop loss and other sections would be FirstTickOfBar = true

                      Comment


                        #12
                        Hi soulfx,

                        I cannot confirm if there are any planned changes for this.

                        However, I am happy to submit a feature request in your behalf to allow orders created with Atm strategy methods to be included with the strategy performance report.

                        Thank you for the great suggestion!
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Chelsea and Soulfx

                          This has been a fascinating thread to read and I've learnt a lot from it. Thanks.

                          All I've done is contribute an idea for some code in post #2 (with a link to another thread) where I have some code that should work (just about with a bit of tweaking) as a breakeven within conventional strategies (unconnected with ATMs).

                          One big advantage of using a strategy (without ATMs) is that you can set all stops, profit targets, breakeven conditions - basically anything - as variables, which is not possible with an ATM.

                          NT7 provides stop loss, profit target and trailing stop methods for use with (non-ATM) strategies, but it doesn't provide anything approaching a breakeven condition: i.e., something that would be placed in Initialize(). This is why I've been attempting to code up something in this line myself.

                          If this were possible in, say, NT8, then, theoretically, it would then be possible to reproduce the power of ATMs within ordinary strategies, and this strikes me as a good idea.

                          Just a thought.

                          Comment


                            #14
                            Hi arbuthnot,

                            A breakeven would be pretty simple to achieve with logic.

                            if (Position.MarketPosition == MarketPosition.Long && Close[0] >= Position.AvgPrice + 10 * TickSize)
                            {
                            SetStopLoss(CalculationMode.Price, Position.AvgPrice);
                            }

                            This would be a breakeven at 10 ticks.

                            However if you would like I can submit a feature request to development to create a function that does this. Would you like me to submit a feature request for this?
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Thanks Arbutnot
                              Yes this is a good suggestion as it adds to the managed portion like SetStopLoss and SetProfitTarget in the initialise. And importantly one doesnt need to differentiate between Firsttickof bar logic in the case where orders are only submitted on bar closes and CalculateOnBarClose = True.
                              This is all handled and managed in the background? Unless i am missing something

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by tony_28217, Today, 07:04 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post tony_28217  
                              Started by flybuzz, Today, 10:33 AM
                              1 response
                              9 views
                              0 likes
                              Last Post flybuzz
                              by flybuzz
                               
                              Started by spencerp92, 10-10-2023, 09:56 AM
                              4 responses
                              304 views
                              0 likes
                              Last Post flybuzz
                              by flybuzz
                               
                              Started by samish18, Yesterday, 10:13 AM
                              1 response
                              26 views
                              0 likes
                              Last Post NinjaTrader_Eduardo  
                              Started by Austiner87, Today, 05:02 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post Austiner87  
                              Working...
                              X