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

Static ATR Targets

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

    Static ATR Targets

    Hi Guys, I have a question on setting a fixed target for ATR. For example I am using this code in an ATM strategy to move target1 on entry to be ATR x 2. I also have a stop based on the same principle.

    AtmStrategyChangeStopTarget(GetAtmStrategyPosition AveragePrice(ATR)-((ATR-GetAtmStrategyPositionAveragePrice(atmStrategyId1) )*2),0, "TARGET1",atmStrategyId1);

    The objectives are as follows (say in a long position)

    1. On entry the ATR stop moves upwards as the price moves upwards. This works as it should.
    2. The 2 x ATR target should be fixed based on the value on entry. The problem with the above code is when the price moves up the ATR target is moving up as well. I want it to fix the ATR target at the point of entry.

    So the question is how would I store and access the value of 2 x ATR at the point of entry so it doesn't move up as the price moves up?

    Thanks in advance
    DJ

    #2
    djkiwi,

    You could use OnExecution() to fix this. It is only called when an order is filled. Please find a link below for more information.

    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Executions

      Hi Adam, thanks for posting that although don't think it will work with an atm strategy. For example if your at Ninja's SampleAtmStrategy attached in line 90 it shows a stop change. Now if changed this to ATR instead I'm not sure how you would apply the Onexecution to this ATM strategy.

      Is there a simpler way of defining a parameter on execution so it doesn't move?
      Thanks
      DJ

      ps: I also found this thread on it and says this doesn't work with ATM strategies. Also I tried to click on the link in post 2 but the link is erroneous.

      Attached Files
      Last edited by djkiwi; 12-18-2011, 01:06 AM.

      Comment


        #4
        ATR targets

        Hi djkiwi;

        Think you might be able to use OnOrderUpdate; also was looking at a volatility breakout strategy which had some tips in it.



        I am new to programming but also have exactly the same problem though I am not accessing my stops and targets through the ATM method. (YET !) Have you found it easier to reference an ATM strategy? Did you try using your own variables and ignoring the facility to reference an ATM? How did it work out? My strategy at present is quite simple (1 entry per direction, 1 target etc) as I am trying to learn the code. I wouldn't be referencing a complicated wizard generated ATM as there would be no need for it.

        I have tried to create a variable 'target' and 'stop_loss' to do the following:

        double target = ATR(5)[0] * 15; (the '15' could also be set as a variable if needed)
        Set.Target = target;
        SetProfitTarget(CalculationMode.Ticks, Target);

        and repeated this for a stop loss with a different multiplier. I believe this goes in 'OnBarUpdate' but it then calculates it for every bar in the event an entry is triggered. Don't know if this is necessary and was looking to see if this can be done under 'OnExecution'

        I have deduced from the help that I need to reset these variables so have used 'OnPositionUpdate'.

        I am led to believe that this will set a fixed target that will not 'move' when the stop does as it is set on execution and is not altered until your position changes. How this works with multiple contracts / scaling into / out of a position I haven't yet found out but hope it gives you an inspirational idea !!

        Have also looked at the link for 'OnExecution' but didn't find it very clear. I wasn't sure where I should be calling the -

        SetProfitTarget and SetStopLoss. (Now believe that this should be called under 'OnExecution'

        What is 'IOrder' and do I need to bother with it if I am only going to have 1 entry per direction? (I believe I need this to reset the target and stop loss)

        Do you know if it matters what order these overrides are put in?

        I have gone :-

        Initialize
        OnBarUpdate
        OnExecution
        OnPositionUpdate

        Do you know of any other links that might help? I am looking, once I have got this little bit to work; to do the same as you and move the stop to BE or a trailing stop once I have achieved a certain profit.
        I was going to use the 'Position.GetProfitLoss' for this in the 'OnBarUpdate' but haven't yet figured out how to cancel the stop loss and/or move it to BE or BE plus 'n' ticks.

        This seems to be getting very complicated for a simple strategy and I feel I'm getting lost in all this. All I want to do is set a profit target and stop loss (submitted on entry) which references a formula using ATR(5)[0]*(a multiplier). Have tried to use the strategy wizard but it doesn't show the generated code for both of these, it just does it somewhere later on. The only bit of research I've done that seems to make any sense is the resetting of both those variables but i cant find clear instruction on how to do this, maybe adam could point me in the right direction please.

        Any thoughts or help greatly appreciated.
        Last edited by stocktraderbmp; 12-18-2011, 04:51 PM. Reason: Further research

        Comment


          #5
          ATR targets

          Found this ;

          The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()


          Seems to answer most of my questions.

          Comment


            #6
            Moving ATRs.

            Hi stocktraderbmp, I am using ATM strategies because I am able to move my targets manually on chart trader dependent on how the orderflow is progressing. See attached volume ladder on the Russell today. I was moving my targets down as strong market driven selling persisted. The problem I find with normal strategies is I cannot move my targets manually so they are not much use for this. I still use normal strategies for fixed targets though.

            I also am also using ATMs to set 3 levels of protection in case the first stop is not triggered. Adding a third party layer like ninjatrader on top of the brokers increases system risks.

            On the other stuff my knowledge is very thin so best direct these questions to the Ninjatrader programmers who provide an excellent service in my opinion.

            Cheers
            DJ
            Attached Files

            Comment


              #7
              Fixed stop

              Hi Adam, any chance of an update on how to trap and set the ATR to the fixed number at the point of execution using ATMs?

              Thanks in advance
              DJ

              Comment


                #8
                I see where your coming from.
                I am trying to fully automate a strategy to remove the discretionary (human) element so have accepted that sometimes I am going to be exiting a big move early.
                Sounds like you are trying to find a way of monitoring your trade after the initial stop and target have been set and whilst you might want to move the stop from within the ATM strategy you don't want the target to move at the same time, but you may want the target to move later but not the stop.
                If this is the case could you reference two ATM strategy's from within your code? (atmstrategyid == atmstopstrategy & atmstrategyid == atmtargetstrategy). One would contain the stops, the other the targets.

                Good luck;

                Ben.

                Comment


                  #9
                  Hi djkiwi,

                  You may consider capturing your ATR value at the time your entry order fills with GetAtmStrategyEntryOrderStatus
                  Last edited by NinjaTrader_RyanM1; 12-20-2011, 11:18 AM.
                  Ryan M.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Tim-c, Today, 03:54 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post Tim-c
                  by Tim-c
                   
                  Started by FrancisMorro, Today, 03:24 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post FrancisMorro  
                  Started by Segwin, 05-07-2018, 02:15 PM
                  10 responses
                  1,772 views
                  0 likes
                  Last Post Leafcutter  
                  Started by Rapine Heihei, 04-23-2024, 07:51 PM
                  2 responses
                  31 views
                  0 likes
                  Last Post Max238
                  by Max238
                   
                  Started by Shansen, 08-30-2019, 10:18 PM
                  24 responses
                  945 views
                  0 likes
                  Last Post spwizard  
                  Working...
                  X