Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

stop price method

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

    stop price method

    I am using the strategy wizard. How can I create an Action to exit (or enter) a position by a stop limit order, where the stop price is equal to the current bar open price plus [previous n bars hi/lo range/y], and the limit price is the [stop price +5] usung ticks.

    I will want to make the previous bars reference value, n and the devisor, y, variables that i can set for testing pruposes.

    thanks

    Nick


    #2
    imported post

    Nick09,

    Your requirements exceeds the capability of the Condition Builder within the Strategy Wizard. You would need to code this directly using the NinjaScriptEditor. You must start the strategy from within the wizard and in the "User Defined Inputs" section, declare the inputs "N" and "Y".

    Within the NinjaScript Editor, you would add code that looked like the following:

    double stopPrice = Open[0] + Range()[N] / Y;
    EnterLongStopLimit(stopPrice +
    5 * TickSize, stopPrice);


    I have included a sample strategy attached in the zip file. Please unzip the contents into the folder C:\Program Files\NinjaTrader 6\bin\Custom\Strategy and you can then open and review it via Tools > Edit NinjaScript > Strategy.

    Ray
    Attached Files
    RayNinjaTrader Customer Service

    Comment


      #3
      imported post

      When using 'Range' (as in your example below), if I want the range of a series of bars i.e. the difference between the highest high and the lowest low of the last 3 bars, how do I request that?

      I think using your example, I'm getting the range of a single bar n bars ago ("rangebars"=n):

      double BuystopPrice = Open[0] + (Range()[rangeBars] / rangeDiv);
      Plot1.Set(BuystopPrice);
      double SellstopPrice = Open[0] - (Range()[rangeBars] / rangeDiv);
      Plot2.Set(SellstopPrice);

      this produces a log error: "error on calling the OnBarUpdate method for indicator Yoda2 on bar 0: Object reference not set to an instance of an object.

      Please could you point me in th right direction.


      Comment


        #4
        imported post

        Try this:

        double highValue = MAX(rangeBars)[0];
        double lowValue = MIN(rangeBars)[0];
        double rangeValue= highValue - lowValue;


        RayNinjaTrader Customer Service

        Comment


          #5
          imported post

          that works- thanks!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          633 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          364 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          105 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          567 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          568 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X