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

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 pmachiraju, 11-01-2023, 04:46 AM
          8 responses
          148 views
          0 likes
          Last Post rehmans
          by rehmans
           
          Started by mattbsea, Today, 05:44 PM
          0 responses
          5 views
          0 likes
          Last Post mattbsea  
          Started by RideMe, 04-07-2024, 04:54 PM
          6 responses
          33 views
          0 likes
          Last Post RideMe
          by RideMe
           
          Started by tkaboris, Today, 05:13 PM
          0 responses
          5 views
          0 likes
          Last Post tkaboris  
          Started by GussJ, 03-04-2020, 03:11 PM
          16 responses
          3,283 views
          0 likes
          Last Post Leafcutter  
          Working...
          X