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

How do you create such a stop & exit?

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

    How do you create such a stop & exit?

    Hi,

    For a long position that I've entered,

    I need to know how to create a stop for : (1 x ATR) - low of entry bar

    and

    Target exit : (2 x ATR) + entry price or Market on Close (MOC), whichever comes first.

    If stop is 2 x ATR or more under the entry price, the setup should be ignored until the next opportunity comes along.

    Can anyone help me with this?

    #2
    Hello,

    You can store these bar values in a double, and then use that double as the price level for your stop and your profit target:

    Code:
    			double stop1 = Low[0] - ATR(14)[0];
    			double target1 = Position.AvgPrice + (ATR(14)[0] * 2);
    						
    			SetStopLoss(stop1);
    			SetProfitTarget(target1);
    Please let me know if you have additional questions.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Thanks for the swift reply, really appreciate it.

      However, I noticed for this line :

      Code:
      double target1 = Position.AvgPrice + (ATR(14)[0] * 2);
      It is based on average price and not on entry price? I am bad at programming so I'm rather just assuming based on the terms used. Also, how do I add in an additional condition where if Low[0] - ATR(14)[0] is lower than 2 x ATR(14)[0], then the trade should be ignored. Is there a way to do that?

      By the way, this code written here, is this done via editing the code of a strategy directly or can it be built with the condition builder when creating a strategy?

      Thank you very much for taking the time to help me, really appreciate it (:
      Last edited by comfy; 08-20-2012, 01:47 AM.

      Comment


        #4
        Hello comfy,
        It might not be possible to do it via the strategy wizard and you have to do it by further coding it via the NinjaScript Editor.
        JoydeepNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Vitamite, Yesterday, 12:48 PM
        3 responses
        17 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by aligator, Today, 02:17 PM
        0 responses
        14 views
        0 likes
        Last Post aligator  
        Started by lorem, 04-25-2024, 09:18 AM
        22 responses
        96 views
        0 likes
        Last Post lorem
        by lorem
         
        Started by sofortune, Today, 10:05 AM
        3 responses
        16 views
        0 likes
        Last Post NinjaTrader_ChristopherJ  
        Started by ETFVoyageur, 05-07-2024, 07:05 PM
        23 responses
        185 views
        0 likes
        Last Post ETFVoyageur  
        Working...
        X