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

managed approach change stop

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

    managed approach change stop

    Hello, using the managed approach and using the SetStopLoss and updating the value in OnBarUpdate

    is there a way to check the profit in ticks of the current strategy position for this instrument to update the stop price or ticks from entry ?

    i currently have the Calculate set to Calculate.OnBarClose - i presume i would need to change this to OnEachTick.

    I can move the enter logic to only Onfirsttickofbar - and the stop / profit updates in the oneachtick section in onbarupdate.

    And do this without using the AtmStrategytemplate example?

    I have looked through the sample of atmstrategy - is this created for each new order ? and so the conditional logic that determines to enter a trade is placed in the
    AtmStrategyCreate section?

    So the objective is to determine if i can handle updating and moving the stop depending on the current profit of the position without needing to use an atmstrategytemplate
    If i need to do so i can

    thanks


    #2
    Hello explorer101,

    Thank you for your post.

    Yes, it would be possible to check the current PnL of the strategy and update a stop price based on that information. If you are wanting everything to continuously update intrabar, you'd want to set it to something other than OnBarClose - however, if you don't mind it only calculating once per bar, you can stay on OnBarClose. Changing to OnPriceChange would be recommended over OnEachTick as OnEachTick has a greater perfomance impact and we're only really interested in the price fluctuations, however, you can experiment with the two.

    Here's a pair of example scripts that you could utilize code from to achieve what you're looking for - one is specifically for modfying stop loss orders and one for using trade performance statistics to control the strategy:





    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      thanks for reply.
      Regarding the ATM strategy piece - if i were to expand to use this the conditional logic goes in the code section AtmStrategyCreate section?
      I need to have an ATM predefined for this to work with the specific name - is this where i then state the quantities and profit stop move aspects or can these be overriden in the
      strategy code ie depending on the number of contracts used?
      Or will i need to update the quantities in the atm strategy predefined before using the strategy ? make sense?
      thanks

      Comment


        #4
        Hello explorer101,

        Thank you for your reply.

        You cannot use this approach with the SampleATMStrategy. Any order handling/stop changing would have to be set in the predefined ATM strategy itself. You also cannot access the pnl of the ATM strategy in the same way as the example in my previous post, where the stops and targets are handled internally in the automated strategy rather than by an ATM strategy.

        That doesn't mean it's not possible to get the PnL for an ATM strategy being used within an automated strategy. Here's an example of doing so:



        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Hello, apologies i think i perhaps confused - i wasnt meaning to intermix the setstoploss in the atmstrategyexample.

          What i was asking in reference to the sample is the conditional logic that determines when to enter a position is this separate to the atm code section or as i had enquired in the atmstrategycreate section?

          Also in the strategy example using atm template - it relies upon the values set in the actual atm - i see from the help and the available methods this seems to be the case.

          So my question above was this will need to be updated for the quantity and stop and profit targets elements based on the number of contracts before running the strateg?
          Do you follow what i am saying? I was trying to glean this from the help but given the use of this i feel it also warrants a more expanded help section

          thanks

          Comment


            #6
            Hello explorer101,

            Thank you for your reply.

            I'm not sure I follow your explanation.

            When using an automated strategy that then triggers an ATM strategy to manage the position, all the automated strategy does is determine when to place an entry and then to place that entry with an ATM Strategy attached. The ATM then takes over the actual management of the entry.

            The values for the Stop and Target in the one that uses the ATM would be controlled from editing the ATM template.

            You have options for how you want to handle the values for the stop and target levels if you are managing the position within the strategy itself as in the first two links I posted in my initial reply. You can hard code those into the strategy, which means you'd have to go in and edit the code for the strategy if you want to change them or you could make it a user input, so you could adjust them from the strategy properties when it's added to the chart. It would be up to you how you prefer to handle that.

            When using SetStopLoss and SetProfitTarget methods to set your stop loss and profit target rather than using an ATM from within the strategy, the stop loss and profit target quantity will be automatically set based on the entry quantity.

            Please let us know if we may be of further assistance to you.
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              Hello, as a follow up to this - in my strategy i have code to update the stop to breakeven after a certain condition and it sets the take profit limit order as well.
              is there a way to handle using the order lines and moving them. Eg
              1. the stop is set to a variable using SetStopLoss( price .....)
              2. this is updated to breakeven but looks to improve the stop price based on another variable - but ensures the stop / risk is not increased.
              3. the take profit is set the in state configure

              with the order lines and i want to shift the take profit ie reduce it or increase it - the strategy which runs on each tick just shifts it back. Same if i then try to move the stop beyond break even to lock in more profit. The order lines shift back.

              I guess that is to be expected but wanted to know if there is a way to handle this so the strategy then accepts the new order line prices.
              Or do i need to then get more complex and handle the order line price updates ?
              Any info appreciated

              thanks

              Comment


                #8
                Hello explorer101,

                Thank you for your reply.

                You would not be able to manually manage orders placed by a strategy using SetStopLoss. If you wish to manually manage the stop and target, you'd want to use a strategy that places an ATM - then you'd be able to manually modify the stops. If you're controlling the stop loss movement from within the strategy as in this case, if you move it it will simply update it on the next OnBarUpdate() call. Automated strategies are meant to be just that - automated.

                Please let us know if we may be of further assistance to you.
                Kate W.NinjaTrader Customer Service

                Comment


                  #9
                  thanks, yes i suspected that was the case and can look at the ATM approach - however the restriction being with this i can only set the entry using my strategy variables. Ie the stop will be exclusively managed by the ATM ? So any attempts by the strategy using the ATM approach will ignore any setstoploss method calls that are made or trigger an error/exception?
                  thanks

                  Comment


                    #10
                    Hello explorer101,

                    Thank you for your reply.

                    That's correct. If you use the ATM approach the ATM would control the stops, not the strategy; SetStopLoss method calls would not work.

                    Please let us know if we may be of further assistance to you.
                    Kate W.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by helpwanted, Today, 03:06 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post helpwanted  
                    Started by Brevo, Today, 01:45 AM
                    0 responses
                    6 views
                    0 likes
                    Last Post Brevo
                    by Brevo
                     
                    Started by aussugardefender, Today, 01:07 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post aussugardefender  
                    Started by pvincent, 06-23-2022, 12:53 PM
                    14 responses
                    242 views
                    0 likes
                    Last Post Nyman
                    by Nyman
                     
                    Started by TraderG23, 12-08-2023, 07:56 AM
                    9 responses
                    384 views
                    1 like
                    Last Post Gavini
                    by Gavini
                     
                    Working...
                    X