Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Min, Max will not work for exiting a position

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

    Min, Max will not work for exiting a position

    I'm trying to get ninjascript to exit a position if the last close is lower than the lowest low of the previous 10 bars. Or the last close is higher than the highest high of the previous 10 bars, for short positions.The code is:

    // Stop loss long
    if (Close[1] < MIN(Low, 10)[1])

    {
    ExitLong("Exit LONG", "Enter LONG");
    }


    // Stop loss short
    if (Close[1] > MAX(High, 10)[1])
    {
    ExitShort ("Exit SHORT", "Enter SHORT");
    }

    Min/Max works when I enter positions. Ex: && High[1] >= MAX(High, 10)[1])

    NinjaTrader doesn't show any mistakes in the code itself so why is it not working?

    #2
    Print out those values to the output window, and you will see the issue.

    Comment


      #3
      Originally posted by sledge View Post
      Print out those values to the output window, and you will see the issue.
      I'm really new to scripting as well as NT so could you please expand a little bit on what that means and how to do it. I saw some info in "Help" but it doesn't say what the output window is. Or rather I don't understand how it would help diagnose or solve this problem.
      Also, as far as I understand "Print" is always written as an action after a condition and never as a condition itself, right?

      Comment


        #4
        Hi Rdaoogle,

        Thank you for the post

        There is a forum post with the same common issue that has a explanation as to why you are running into a problem.
        http://www.ninjatrader.com/support/f...221#post210221

        Basically, you are referencing the same bar with the MIN[1]. Since Close can never be lower than Low or higher than High.

        An example alternative code -
        Code:
        if(Close[0] < MIN(Low,20)[1]) //Starts evaluating the 10-bar highest high starting at one bar prior to the close.
        Please let me know if I can be of further assistance
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Sorry, I am on my phone.

          In control center, menu tools, hclick output window.


          Then, look up c# Print statement.

          Put before your conditions some thing like:

          Print ("close[1]="+ Close[1] );

          then do that for your other comparison.

          you see the values and see why you never get in.



          Originally posted by rdaoogle View Post
          I'm really new to scripting as well as NT so could you please expand a little bit on what that means and how to do it. I saw some info in "Help" but it doesn't say what the output window is. Or rather I don't understand how it would help diagnose or solve this problem.
          Also, as far as I understand "Print" is always written as an action after a condition and never as a condition itself, right?

          Comment


            #6
            Thanks guys, that made it work
            Last edited by rdaoogle; 05-01-2013, 12:29 PM.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            576 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            334 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            553 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            551 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X