Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting stops & targets

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

    Setting stops & targets

    How can I set my stop to the value of 2 times the ATR of the current bar that I enter on and my target 2 times the value of my stop. I keep getting errors compiling. Can some please help??!!

    Thanks!

    #2
    fxmutual,

    Welcome to the forums. Here is one possible way to do this:

    2 times the ATR of the current bar that I enter on and my target 2 times the value of my stop
    Code:
    double stopPrice           = 2 * ATR(10)[BarsSinceEntry()];
    double targetPrice	= 2 * stopPrice;
    This is just a literal translation of what you requested, but I don't see it working in a strategy. The prices won't typically be near market prices, so you may want to look into refining this a bit more. If you are just getting started building strategies, would recommend the point and click strategy wizard to start, and these strategy building code tutorials are also helpful:
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the help. I am new. And I am going though all the material I can get my hands on. LOL

      The logic I am trying to work out is if the ATR is showing for example 50, then, for a long I want my stop to 100 pips below the entry and I want my target 200 pips above the entry.

      Like a 1:2 risk reward ratio.


      What section for the program would I put your code example in that you posted above ???

      Comment


        #4
        I see. In that case you could work with Position.AvgPrice to get the entry price simply. This property returns zero when not in a position, so you'll see in snippet below it's only checked when you are not flat.

        If you're just getting started, OnBarUpdate() would be the place for this. This is only one of a few ways you could do this, and this snippet works best if you use the standard exit methods to submit your orders like ExitLongStop(), and ExitLongLimit().

        Code:
        if (Position.MarketPosition != MarketPosition.Flat)
        {
        	double stopPrice   = Position.AvgPrice - (2 * ATR(10)[BarsSinceEntry()]);
        	double targetPrice = Position.AvgPrice + 2 * (2 * ATR(10)[BarsSinceEntry()]);
        }
        Last edited by NinjaTrader_RyanM1; 07-25-2012, 03:24 PM.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Thanks for all your help!

          I am not sure but the code you posted for we....that updates on every bar close right?

          It seem to me that would update my stop and target on every bar, I would just like to get the value of the ATR on my entry bar only and use for a fixed stop and target. Any ideas?

          Comment


            #6
            Yeah it fixes the ATR value at the point of entry, since it indexes the value using BarsSinceEntry()

            Even still, this idea can be done a bit cleaner with Set methods and mode ticks. You could do that with something like this:

            Code:
            double stopTicks   = Position.AvgPrice - (2 * ATR(10)[BarsSinceEntry()]);
            double targetTicks = 2 * stopTicks;
            	
            SetStopLoss(CalculationMode.Ticks, stopTicks);
            SetProfitTarget(CalculationMode.Ticks, targetTicks);
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            647 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            572 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            573 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X