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 charlesugo_1, 05-26-2026, 05:03 PM
          0 responses
          51 views
          0 likes
          Last Post charlesugo_1  
          Started by DannyP96, 05-18-2026, 02:38 PM
          1 response
          142 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 05-11-2026, 05:56 AM
          0 responses
          160 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 05-10-2026, 08:12 PM
          0 responses
          96 views
          0 likes
          Last Post CarlTrading  
          Started by Hwop38, 05-04-2026, 07:02 PM
          0 responses
          275 views
          0 likes
          Last Post Hwop38
          by Hwop38
           
          Working...
          X